# template error while templating string: unexpected char u'\\\\' at 127

**URL:** <https://forum.ansible.com/t/template-error-while-templating-string-unexpected-char-u-at-127/17464>\
**Category:** Ansible Project\
**Created:** [February 7, 2015, 2:38am UTC](https://forum.ansible.com/t/template-error-while-templating-string-unexpected-char-u-at-127/17464 "2015-02-07T02:38:02Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![cdwertmann](https://avatars.discourse-cdn.com/v4/letter/c/9e8a1a/32.png) [@cdwertmann](https://forum.ansible.com/u/cdwertmann)\
**Post date:** [February 7, 2015, 2:38am UTC](https://forum.ansible.com/t/template-error-while-templating-string-unexpected-char-u-at-127/17464/1 "2015-02-07T02:38:02Z")

</div>

Hi!

The following ansible snippet worked fine in 1.7, but throws an error in 1.8. I suspect it has something to do with the {% … %} string I’m trying to insert into the file. I tried different ways to escape it, but can’t find the solution.

- name: add logon banner  
lineinfile: dest=/usr/lib/python2.7/dist-packages/horizon/templates/auth/\_login.html regexp=‘^ ’ line=" {% include "banner.html" %}"

fatal: [node] =\> template error while templating string: unexpected char u’\’ at 127

Without escaping the double quotes I get a different error:

lineinfile: dest=/usr/lib/python2.7/dist-packages/horizon/templates/auth/\_login.html regexp=‘^ ’ line=’ {% include “banner.html” %}’

fatal: [node] =\> an unexpected type error occurred. Error was no loader for this environment specified

I appreciate any suggestions!

Christoph

---

<div class="post-metadata">

**Author:** ![Giovanni\_Tirloni](https://avatars.discourse-cdn.com/v4/letter/g/71c47a/32.png) [@Giovanni\_Tirloni](https://forum.ansible.com/u/Giovanni_Tirloni)\
**Post date:** [February 8, 2015, 10:26am UTC](https://forum.ansible.com/t/template-error-while-templating-string-unexpected-char-u-at-127/17464/2 "2015-02-08T10:26:20Z")

</div>

Does it work if you use pure YAML syntax?

- name: add logon banner  
&nbsp;&nbsp;lineinfile:  
&nbsp;&nbsp;&nbsp;&nbsp;dest:  
&nbsp;&nbsp;&nbsp;&nbsp;/usr/lib/python2.7/dist-packages/horizon/templates/auth/\_login.html  
&nbsp;&nbsp;&nbsp;&nbsp;regexp: '^ \</fieldset\>'  
&nbsp;&nbsp;&nbsp;&nbsp;line: ' \</fieldset\>{% include "banner.html" %}'

Giovanni

---

<div class="post-metadata">

**Author:** ![cdwertmann](https://avatars.discourse-cdn.com/v4/letter/c/9e8a1a/32.png) [@cdwertmann](https://forum.ansible.com/u/cdwertmann)\
**Post date:** [February 8, 2015, 1:19pm UTC](https://forum.ansible.com/t/template-error-while-templating-string-unexpected-char-u-at-127/17464/3 "2015-02-08T13:19:10Z")

</div>

Unfortunately not. I tried:

- name: add logon banner

lineinfile:

dest: /usr/lib/python2.7/dist-packages/horizon/templates/auth/\_login.html

regexp: ‘^ ’

line: ’ {% include “banner.html” %}’

TASK: [add logon banner] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

fatal: [node11] =\> an unexpected type error occurred. Error was no loader for this environment specified

---

<div class="post-metadata">

**Author:** ![vaida.dan](https://avatars.discourse-cdn.com/v4/letter/v/5daacb/32.png) [@vaida.dan](https://forum.ansible.com/u/vaida.dan)\
**Post date:** [February 8, 2015, 6:04pm UTC](https://forum.ansible.com/t/template-error-while-templating-string-unexpected-char-u-at-127/17464/4 "2015-02-08T18:04:08Z")

</div>

Have you tried the replace module?  
Would it be feasible for you to template that file?

---

<div class="post-metadata">

**Author:** ![cdwertmann](https://avatars.discourse-cdn.com/v4/letter/c/9e8a1a/32.png) [@cdwertmann](https://forum.ansible.com/u/cdwertmann)\
**Post date:** [February 8, 2015, 11:59pm UTC](https://forum.ansible.com/t/template-error-while-templating-string-unexpected-char-u-at-127/17464/5 "2015-02-08T23:59:27Z")

</div>

What I really want is to add that line to the file. Templating would mean that I need to change my template everytime the original file changes.

I tried to template it anyway, but it also gives me an error since the content of the file contains curly braces. Apparently there used to be a way to change the variable\_start\_string, but that feature has been removed. It seems that I need to wait for this issue to be resolved first: [https://github.com/ansible/ansible/issues/10031](https://github.com/ansible/ansible/issues/10031)

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [February 9, 2015, 1:33am UTC](https://forum.ansible.com/t/template-error-while-templating-string-unexpected-char-u-at-127/17464/6 "2015-02-09T01:33:39Z")

</div>

try escaping with raw

ineinfile: dest=/usr/lib/python2.7/dist-packages/horizon/templates/auth/\_login.html  
regexp='^ \</fieldset\>' line=" \</fieldset\>{% raw %}{% include  
\"banner.html\" %}(% endraw %}"

---

<div class="post-metadata">

**Author:** ![cdwertmann](https://avatars.discourse-cdn.com/v4/letter/c/9e8a1a/32.png) [@cdwertmann](https://forum.ansible.com/u/cdwertmann)\
**Post date:** [February 9, 2015, 2:17am UTC](https://forum.ansible.com/t/template-error-while-templating-string-unexpected-char-u-at-127/17464/7 "2015-02-09T02:17:33Z")

</div>

Brian, thanks a lot, this is working!

Cheers,

Christoph
