Jinja template
A text file containing Jinja expressions that Ansible fills in with each host's variables to produce a finished file.
In more detail
By convention it ends in .j2 and lives in a templates directory beside the playbook or role. Whitespace, quoting and line endings in the template are part of the output, so check the rendered file when a program is fussy about formatting.
Example
templates/message.j2Related terms
- Jinja — A templating language for Python tools that fills placeholders in text, written inside double curly braces, with values and simple logic.
- template module — The module that fills in a Jinja template with variables and writes the result to a file on each host.
- whitespace — Characters that show as blank space, such as spaces, tabs and line breaks.
Taught in
- Loops — Ansible Configuration Management at Scale
- Templates With Jinja — Ansible Configuration Management at Scale
- The Standard Directory Layout And Roles — Ansible Configuration Management at Scale
- Facts And Magic Variables: Let Each Node Describe Itself — RHCE in Ansible (EX294): Automate Red Hat Systems
- Users And Groups From A List, With Passwords That Settle — RHCE in Ansible (EX294): Automate Red Hat Systems
- Jinja Templates: One File, A Different Text Per Host — RHCE in Ansible (EX294): Automate Red Hat Systems