jinja2 templating error : template error while templating string: unexpected char '@'

33 views
Skip to first unread message

JiElPe-Fr38

unread,
Jul 12, 2019, 10:20:42 AM7/12/19
to Ansible Project
Dear all,

I have defined a var which contains some special characters (actually, a password in a vault).
Let's assume the vault contains :
myPasswd: foo@bar

There is no problem when creating the encrypted file.

When I use it somewhere in a playbook, for example :
password: "{{ myPasswd }}"

I get the error message in the subject :

jinja2 templating error : template error while templating string: unexpected char '@'  at 5. String: {{foo@bar}}"

So, though the var is encrypted in the vault (and can be correctl decrypted when viewing or editing), and is actually decrypted when used, it cannot be "jinja2 evaluated".
Note that when removing such a character (! has the same problem, and I often use it in passwords), there is no more problem and the var is correctly set and used.
It is clear not a vault problem.

Could it be a bug around jinja2 templating, or is there something to use in order to escape such characters ?

Thanks for your help !

Best Regards
J-L

kdt

unread,
Jul 15, 2019, 6:44:54 AM7/15/19
to Ansible Project
E.g. I had to drop usage of dash in variable names in order to get my playbook to parse without errors.

Brian Coca

unread,
Jul 15, 2019, 9:32:36 AM7/15/19
to Ansible Project
When defining values with special characters that might prevent
templating you can use !unsafe:

myPasswd: !unsafe foo@bar

--
----------
Brian Coca
Reply all
Reply to author
Forward
0 new messages