From the course: Red Hat Certified Engineer (EX294) Cert Prep: 2 Using Ansible Playbooks

Unlock the full course today

Join today to access over 22,700 courses taught by industry experts or purchase this course individually.

Using Jinja2 template files

Using Jinja2 template files

From the course: Red Hat Certified Engineer (EX294) Cert Prep: 2 Using Ansible Playbooks

Start my 1-month free trial

Using Jinja2 template files

- [Instructor] Sometimes it's hard to know where Ansible ends and Jinja2 starts. Jinja2 is used for templating but also for accessing variables, using data filters and tests, some of which we've already discussed. Ansible uses Jinja2 templating to access variables in playbooks. For this we use the double curly braces syntax. If you want to access a variable element, you can use square brackets within the double curly braces. We can use Jinja2 filters for formatting data, creating lists, creating random data such as MAC addresses and random numbers, debugging, as well as manipulating text and data in variables and much more. See the Ansible playbooks filters' page for more information. We can use Ansible own conditionals, such as the when and until keywords, to create dynamic content. But when and until work best when combined with a Jinja2 test, such as is file, is directory, is failed, is succeeded, or even text…

Contents