# jinja2: escaping special chars

**URL:** <https://forum.ansible.com/t/jinja2-escaping-special-chars/28954>\
**Category:** Ansible Project\
**Created:** [November 6, 2018, 11:04am UTC](https://forum.ansible.com/t/jinja2-escaping-special-chars/28954 "2018-11-06T11:04:22Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![christian.tremel](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@christian.tremel](https://forum.ansible.com/u/christian.tremel)\
**Post date:** [November 6, 2018, 11:04am UTC](https://forum.ansible.com/t/jinja2-escaping-special-chars/28954/1 "2018-11-06T11:04:22Z")

</div>

i want to generate a config for syslogd from template. as there are some “special” chars in the config, the ‘\*’ char in this case, ansible has some problems to run the template.  
how to i tell ansible/jinja2 to treat the star as an literal?

error:

AnsibleError: template error while templating string: expected token ‘end of statement block’, got ‘\*’. String: # {{ ansible\_managed }}

template:

`

# {{ ansible\_managed }}

auth.info /var/log/syslog/auth rotate compress size 10m files 10  
_.info /var/log/syslog/messages rotate compress size 10m files 10  
local2._ /var/log/syslog/sudo rotate compress size 10m files 10  
{% if ( (inventory\_lparname not in groups[‘HA\_HOST’] | default()) and  
(inventory\_lparname not in groups[‘DMZ\_HOST’] | default()) ):  
\*.info @1.2.3.4  
{% endif %}  
{% if inventory\_lparname in groups[‘HA\_HOST’] | default() %}

# HACMP Config

\*.info @1.2.3.4

# PowerHA SystemMirror Critical Messages

local0.crit /dev/console

# PowerHA SystemMirror Informational Messages

local0.info /var/hacmp/adm/cluster.log rotate size 1m files 8

# PowerHA SystemMirror Messages from Cluster Scripts

user.notice /var/hacmp/adm/cluster.log rotate size 1m files 8

# PowerHA SystemMirror Messages from Cluster Daemons

daemon.notice /var/hacmp/adm/cluster.log rotate size 1m files 8

caa.info /var/adm/ras/syslog.caa rotate size 1m files 10  
{% endif %}  
{% if (inventory\_lparname in groups[‘DMZ\_HOST’] | default())  
\*.info @1.2.3.4  
{% endif %}  
{% if ( (‘some\_host’ in ansible\_hostname) or  
(‘`some_host`’ in ansible\_hostname) or  
(‘`some_host`’ in ansible\_hostname) or  
(‘`some_host`’ in ansible\_hostname) or  
(‘`some_host`’ in ansible\_hostname) or  
(‘`some_host`’ in ansible\_hostname) ):

# Trusted Logging

\*.info /dev/vlog0  
{% endif %}

# ASO log configuration

aso.notice /var/log/aso/aso.log rotate size 128k time 7d  
aso.info /var/log/aso/aso\_process.log rotate size 1024k  
aso.debug /var/log/aso/aso\_debug.log rotate size 8m compress

mail.debug /var/log/syslog/mail rotate time 7d files 4 compress

`

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [November 6, 2018, 12:15pm UTC](https://forum.ansible.com/t/jinja2-escaping-special-chars/28954/2 "2018-11-06T12:15:31Z")

</div>

Thats the default.

Your problem is that your first and last if statement is missing the closing tag %}, you have used a colon.

---

<div class="post-metadata">

**Author:** ![christian.tremel](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@christian.tremel](https://forum.ansible.com/u/christian.tremel)\
**Post date:** [November 6, 2018, 12:32pm UTC](https://forum.ansible.com/t/jinja2-escaping-special-chars/28954/3 "2018-11-06T12:32:18Z")

</div>

hmm…added the missing tags…now another error comes up.

AnsibleError: template error while templating string: unexpected ‘.’. String: # {{ ansible\_managed }}

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [November 6, 2018, 2:44pm UTC](https://forum.ansible.com/t/jinja2-escaping-special-chars/28954/4 "2018-11-06T14:44:41Z")

</div>

Did you also remove the colon and checked all the if's?  
I see there is also another one that is wrong.

If yes you need to post the file again since you know have done changes to it.
