Templates for Ansibles
Ansible templates generate configuration files from Jinja2 files, filling in variables per host. The template module renders a .j2 file and copies it to the target, while modules such as copy, file and lineinfile manage static files, permissions and small edits. Handlers restart services only when a file changes.
Stage: Playbook Skills · Part of the Ansible roadmap · Last reviewed 19 November 2026
What to learn in Templates
- Write a Jinja2 template with variables, loops and conditionals
- Deploy a rendered config file with the template module
- Set owner, group and mode on files with the file module
- Trigger a handler to reload a service only after a change
- Choose between copy, template and lineinfile for a given edit
Templates interview questions
What is the difference between the copy and template modules?
copy transfers a file or inline content exactly as it is. template first processes a Jinja2 file, substituting variables and evaluating loops and conditions for each host, and then writes the result. Use template when the content differs between hosts or environments.
What are handlers in Ansible?
A handler is a task that runs only when notified by another task that reported a change, and it runs once at the end of the play even if notified multiple times. They are typically used to restart or reload a service after its configuration file changes.
Where Templates fits in the Ansible roadmap
Templates belongs to the Playbook Skills stage (intermediate level). Write better automation.
Other units in this stage
Back to the full Ansible roadmap