template

Collection: builtin

Full Name: parallax.builtin.template

Aliases: ansible.builtin.template, template

Synopsis

Render a Jinja2 template on the controller and install the result

Parameters

NameTypeRequiredDefaultDescription
srcstringyesTemplate file on the controller
deststringyesPath on the target the rendered template is written to
varsmap[string]anymap[]Extra variables layered on top of the host namespace for this render
modestringPermission mode of the rendered file
ownerstringName or numeric id of the user that should own the file
groupstringName or numeric id of the group that should own the file
backupboolfalseCreate a timestamped backup of the destination before overwriting it
forcebooltrueReplace the destination when it exists and differs
followboolfalseFollow symlinks on the destination when applying ownership
validatestringCommand run against the staged file before it is moved into place; %s is replaced with the staged path
newline_sequencestring`
`Line ending of the rendered file: “\n”, “\r” or “\r\n”
block_start_stringstring{%String marking the start of a block
block_end_stringstring%}String marking the end of a block
variable_start_stringstring{{String marking the start of an expression
variable_end_stringstring}}String marking the end of an expression
comment_start_stringstring{#String marking the start of a comment
comment_end_stringstring#}String marking the end of a comment
trim_blocksbooltrueRemove the first newline after a block tag
lstrip_blocksboolfalseStrip leading whitespace from the start of a line to a block tag

Example

- name: Render the vhost from a template
  template:
    src: templates/vhost.conf.j2
    dest: /etc/nginx/conf.d/app.conf
    owner: root
    mode: "0644"
    validate: nginx -t -c %s