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

**URL:** <https://forum.ansible.com/t/jinja2-templating-error-template-error-while-templating-string-unexpected-char/30770>\
**Category:** Ansible Project\
**Created:** [July 12, 2019, 2:20pm UTC](https://forum.ansible.com/t/jinja2-templating-error-template-error-while-templating-string-unexpected-char/30770 "2019-07-12T14:20:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![JiElPe-Fr381](https://avatars.discourse-cdn.com/v4/letter/j/c67d28/32.png) [@JiElPe-Fr381](https://forum.ansible.com/u/JiElPe-Fr381)\
**Post date:** [July 12, 2019, 2:20pm UTC](https://forum.ansible.com/t/jinja2-templating-error-template-error-while-templating-string-unexpected-char/30770/1 "2019-07-12T14:20:41Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![kdt](https://avatars.discourse-cdn.com/v4/letter/k/85f322/32.png) [@kdt](https://forum.ansible.com/u/kdt)\
**Post date:** [July 15, 2019, 10:44am UTC](https://forum.ansible.com/t/jinja2-templating-error-template-error-while-templating-string-unexpected-char/30770/2 "2019-07-15T10:44:54Z")

</div>

Kindly refer to [Creating valid variable names](https://docs.ansible.com/ansible/latest/user_guide/playbooks_variables.html#creating-valid-variable-names) - [https://docs.ansible.com/ansible/latest/user\_guide/playbooks\_variables.html#creating-valid-variable-names](https://docs.ansible.com/ansible/latest/user_guide/playbooks_variables.html#creating-valid-variable-names).  
E.g. I had to drop usage of dash in variable names in order to get my playbook to parse without errors.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [July 15, 2019, 1:32pm UTC](https://forum.ansible.com/t/jinja2-templating-error-template-error-while-templating-string-unexpected-char/30770/3 "2019-07-15T13:32:05Z")

</div>

When defining values with special characters that might prevent  
templating you can use !unsafe:

myPasswd: !unsafe foo@bar
