# error: unexpected char u'\_' for template action

**URL:** <https://forum.ansible.com/t/error-unexpected-char-u-for-template-action/14087>\
**Category:** Ansible Project\
**Created:** [December 6, 2013, 9:19am UTC](https://forum.ansible.com/t/error-unexpected-char-u-for-template-action/14087 "2013-12-06T09:19:20Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![rella.guo](https://avatars.discourse-cdn.com/v4/letter/r/d2c977/32.png) [@rella.guo](https://forum.ansible.com/u/rella.guo)\
**Post date:** [December 6, 2013, 9:19am UTC](https://forum.ansible.com/t/error-unexpected-char-u-for-template-action/14087/1 "2013-12-06T09:19:20Z")

</div>

**I have one template file like that:**  
…  
ErrorDocument 403 /customerror/$403\_error\_page

…

**For ansible 1.4, I change the template to:**  
…  
ErrorDocument 403 /customerror/{{ 403\_error\_page }}

…

**Then I got the error:**

fatal: [192.168.126.143] =\> {‘msg’: “file: /home/playbooks/templates/conf/mod.conf, line number: 15, error: unexpected char u’_’ at 483", ‘failed’: True}  
fatal: [192.168.126.143] =\> {‘msg’: ‘One or more items failed.’, ‘failed’: True, ‘changed’: False, ‘results’: [{‘msg’: "file: /home//playbooks/templates/conf/mod.conf, line number: 15, error: unexpected char u’_’ at 483”, ‘failed’: True}]}

Who knows the reason? Thanks.

---

<div class="post-metadata">

**Author:** ![Fred\_Badel](https://avatars.discourse-cdn.com/v4/letter/f/f07891/32.png) [@Fred\_Badel](https://forum.ansible.com/u/Fred_Badel)\
**Post date:** [December 6, 2013, 9:42am UTC](https://forum.ansible.com/t/error-unexpected-char-u-for-template-action/14087/2 "2013-12-06T09:42:50Z")

</div>

Hi,

Not sure this is the cause, but a variable should always start with a letter  
see [http://www.ansibleworks.com/docs/playbooks\_variables.html#id11](http://www.ansibleworks.com/docs/playbooks_variables.html#id11)

hth

fred

---

<div class="post-metadata">

**Author:** ![rella.guo](https://avatars.discourse-cdn.com/v4/letter/r/d2c977/32.png) [@rella.guo](https://forum.ansible.com/u/rella.guo)\
**Post date:** [December 6, 2013, 9:49am UTC](https://forum.ansible.com/t/error-unexpected-char-u-for-template-action/14087/3 "2013-12-06T09:49:55Z")

</div>

OK. This is a new constraint. If I use $foo format, it works well.  
Anyway, thank you much very!

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [December 6, 2013, 1:19pm UTC](https://forum.ansible.com/t/error-unexpected-char-u-for-template-action/14087/4 "2013-12-06T13:19:07Z")

</div>

This is _almost_ true.

Jinja2 variables should follow standard Python/programming language variable constraints.

You should definitely rename your variables, but if you technically need to access them by name you can still do so.

{{ hostvars[inventroy\_hostname][“403\_error\_page”] }}

Will still allow you to get at a variable that doesn’t have a valid variable name.

In any case, you should rename your variables as $legacy variable syntax will be removed in 1.6.
