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

4,891 views
Skip to first unread message

cdwer...@gmail.com

unread,
Feb 6, 2015, 9:38:02 PM2/6/15
to ansible...@googlegroups.com
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='^  </fieldset>' line="  </fieldset>{% 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='^  </fieldset>' line='  </fieldset>{% include "banner.html" %}'

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

I appreciate any suggestions!

Christoph

Giovanni Tirloni

unread,
Feb 8, 2015, 5:26:30 AM2/8/15
to ansible...@googlegroups.com
Does it work if you use pure YAML syntax?

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

Giovanni

cdwer...@gmail.com

unread,
Feb 8, 2015, 8:19:10 AM2/8/15
to ansible...@googlegroups.com
Unfortunately not. I tried:

    - name: add logon banner

      lineinfile:

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

        regexp: '^  </fieldset>'

        line: '  </fieldset>{% include "banner.html" %}'

 

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

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

Dan Vaida

unread,
Feb 8, 2015, 1:04:08 PM2/8/15
to ansible...@googlegroups.com
Have you tried the replace module?
Would it be feasible for you to template that file?

cdwer...@gmail.com

unread,
Feb 8, 2015, 6:59:27 PM2/8/15
to ansible...@googlegroups.com
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

Brian Coca

unread,
Feb 8, 2015, 8:33:42 PM2/8/15
to ansible...@googlegroups.com
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 %}"



--
Brian Coca

cdwer...@gmail.com

unread,
Feb 8, 2015, 9:17:33 PM2/8/15
to ansible...@googlegroups.com
Brian, thanks a lot, this is working!

Cheers,

Christoph
Reply all
Reply to author
Forward
0 new messages