Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To utilize variables in an Ansible Jinja2 template, you need to use the double curly braces notation, {{ variable_name }}, to enclose the variable name in the template file.

For example, let's say you have defined a variable named "my_var" in your Ansible playbook or inventory file. You can use the variable in your Jinja2 template as follows:

My variable value is {{ my_var }}.

When Ansible runs the template task, it will replace the variable name with its value, generating the resulting text:

My variable value is some_value.

Note that you can also use variables in conditional blocks or loops in your Jinja2 templates using the same notation.