jinja2: escaping special chars

73 views
Skip to first unread message

christia...@itsv.at

unread,
Nov 6, 2018, 6:04:23 AM11/6/18
to Ansible Project
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



Kai Stian Olstad

unread,
Nov 6, 2018, 7:15:48 AM11/6/18
to ansible...@googlegroups.com
On 06.11.2018 12:04, christia...@itsv.at wrote:
> 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?

Thats the default.

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

--
Kai Stian Olstad

christia...@itsv.at

unread,
Nov 6, 2018, 7:32:19 AM11/6/18
to Ansible Project
hmm..added the missing tags...now another error comes up.

AnsibleError: template error while templating string: unexpected '.'. String: # {{ ansible_managed }}

Kai Stian Olstad

unread,
Nov 6, 2018, 9:45:00 AM11/6/18
to ansible...@googlegroups.com
On Tuesday, 6 November 2018 13:32:18 CET christia...@itsv.at wrote:
> hmm..added the missing tags...now another error comes up.
>
> AnsibleError: template error while templating string: unexpected '.'.
> String: # {{ ansible_managed }}

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.


--
Kai Stian Olstad


Reply all
Reply to author
Forward
0 new messages