template
template module
Process Jinja2 templates and write the result to a file on the target host. This module renders templates with variables from the playbook context.
Examples
- name: Template a configuration file
template:
src: nginx.conf.j2
dest: /etc/nginx/nginx.conf
mode: '0644'
- name: Template from role templates directory
template:
src: app.conf.j2
dest: /etc/myapp/app.conf
- name: Template with backup
template:
src: important.conf.j2
dest: /etc/important.conf
mode: '0600'
Note: When used in roles, the template module will first look for templates in the role's templates/
directory before checking other locations. Templates have access to all variables in the current context, including facts, registered variables, and playbook variables.
Module Capabilities
- Has Revert: true
- Provides Variables: None
Inputs
Parameter | Type | Description | Required | Default | Choices |
---|---|---|---|---|---|
dest | string | Path to write the templated file on the target host. | true | ||
mode | string | File permissions to set on the destination file (e.g., '0644', '0755'). | false | ||
src | string | Path to the Jinja2 template file on the local machine. | true |
Outputs
No outputs.