Ansible - Resolve "Encountered unknown tag"

Let's say you have a file named bar.j2 in your templates directory.

/etc/ansible/roles/foo/templates/bar.j2

 

And let's say bar.j2 contains the following.

{%Y}

 

Since templates are part of roles, lets say you have a playbook that invokes the foo role.

---
- hosts: all
  roles:
    - role: foo

 

And let's say /etc/ansible/roles/foo/tasks/main.yml contains the following.

- name: copy ipv4.j2 to /tmp/ipv4.conf
  template:
    src: ipv4.j2
    dest: /tmp/ipv4.conf

 

Running this play would return Encounted unknown tag 'Y' because {%Y} is built in jinja2 syntax.

Encounted unknown tag 'Y'

 

In this scenario, {% raw %} and {% endraw %} are wrapped around the {%Y} built in jinja2 syntax so that {%Y} is not interpreted as jinja2.

{% raw %}{%Y}{% endraw %}

 



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.





Please enter f1eb3 in the box below so that we can be sure you are a human.




Comments


July 23rd, 2021 by Steve
This helped me out with an issue with the www.conf file of PHP-FPM which had %Y in the comments of some settings.

Web design by yours truely - me, myself, and I   |   jeremy.canfield@freekb.net   |