Templates with Jinja2

In the previous section, we used variables with the Jinja2 syntax of {{ variable }}. While you can do a lot of complex things in Jinja2, luckily, we only need some of the basic things to get started.

Jinja2 (http://jinja.pocoo.org/) is a full-featured, powerful template engine that originated in the Python community. It is widely used in Python web frameworks such as Django and Flask.

For now, it is enough to just keep in mind that Ansible utilizes Jinja2 as the template engine. We will revisit the topics of Jinja2 filters, tests, and lookups as the situations call for them. You can find more information on the Ansible Jinja2 template here: http://docs.ansible.com/ansible/playbooks_templating.html.

Get Mastering Python Networking - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.