The template Module & .j2 Files
Deploy a rendered file to a host.
Static Files Are Not Enough
The copy module ships a file unchanged. But config files often need a port or hostname that differs per server, so static copies fall short. 🤔
Enter the template Module
The template module renders a file through Jinja2 first, filling in variables, then copies the result to the host.
- name: Deploy config
template:
src: nginx.conf.j2
dest: /etc/nginx/nginx.confAll lessons in this course
- The template Module & .j2 Files
- Variables & Expressions in Jinja2
- Loops & if Blocks in Templates
- Filters: default, join & upper