March 2019
Intermediate to advanced
412 pages
9h 49m
English
The name variable is actually very simple. It just provides a way to access the name of the macro as a variable, perhaps for further manipulation or usage. The following template includes a macro that references the name of the macro to render it in the output:
{% macro test() -%}
{{ test.name }}
{%- endmacro -%}
{{ test() }}
Let's say we were to create demo-macro.j2 with this template and the following template-demo-macro.yaml playbook:
---- name: demo the template hosts: localhost gather_facts: false vars: data_dirs: ['/', '/foo', '/bar'] tasks: - name: pause with render pause: prompt: "{{ lookup('template', 'demo-macro.j2') }}"
We would get the following output:
As we see from this test run, our template simply rendered with the ...
Read now
Unlock full access