Manipulating configuration files by hand is a tedious and error-prone task, and equally, performing pattern matching to make changes to existing files is risky, and ensuring that the patterns are reliable and accurate is a time-consuming task. Whether you are using Ansible to define configuration file content, to perform variable substitution in tasks, evaluate conditional statements, or beyond, templating comes into play with nearly every Ansible playbook. In fact, given the importance of this task, it could be said that templating is the lifeblood of Ansible.
The templating engine that was employed by Ansible is Jinja2, a modern and designer-friendly templating language for Python. Jinja2 deserves a book all of its own, but in this chapter, we will cover some of the more common usage patterns of Jinja2 templating in Ansible to get you...