0Pricing
Ansible Academy · Lesson

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.conf

All lessons in this course

  1. The template Module & .j2 Files
  2. Variables & Expressions in Jinja2
  3. Loops & if Blocks in Templates
  4. Filters: default, join & upper
← Back to Ansible Academy