template module
The module that fills in a Jinja template with variables and writes the result to a file on each host.
In more detail
src names the template on the control node, dest names the file to write, and the rendering happens separately for every host, so each gets its own values. It compares the rendered text with the existing file and reports changed only when they differ, which makes it idempotent and a natural trigger for a handler.
Related terms
- Jinja — A templating language for Python tools that fills placeholders in text, written inside double curly braces, with values and simple logic.
- Jinja template — A text file containing Jinja expressions that Ansible fills in with each host's variables to produce a finished file.
- handler — A task that runs only when another task notifies it and reports changed, typically to reload or restart a service.
- copy module — The module that puts a file on a host, either copied from the control node or written from content given in the task.
Taught in
- Templates With Jinja — Ansible Configuration Management at Scale
- The Standard Directory Layout And Roles — Ansible Configuration Management at Scale
- Roles: The Directory Ansible Expects, Defaults And Handlers — 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
- Mock Exam, Part 1: Seven Tasks Across Three Sections — RHCE in Ansible (EX294): Automate Red Hat Systems