Jinja2 is a modern and designer-friendly templating language for Python frameworks. It is fast, reliable and widely used for dynamic file generation based on its parameter. In this blog, I like to share how and where jinja2 template language used in Ansible and how we can create better Ansible playbook.
How it works
The Jinja variables and expressions indicated using the default delimiters as follows:
- {% … %} for control statements (conditions)
- {{ … }} for expressions (variables)
- {# … #} for comments (describe the task)
Here’s an example Jinja expressions:
- hosts: 127.0.0.1
vars_files:
- vars.yml
tasks:
- name: Checking the IP address
debug:
msg: "IP address {{ ip }}"
- name: Checking OS name
debug:
msg: "OS NAME {{ os_name }}"
Variable definitions are needed for Jinja to resolve expressions. In the …
[Read more]