template error

602 views
Skip to first unread message

simonq

unread,
Nov 11, 2014, 4:58:23 PM11/11/14
to ansible...@googlegroups.com
I get template error while templating string: unexpected '.' when running this task using ansible 1.8 (devel fa953e162e). Used to work with previous version I was running (1d04e4b3d2). Any thoughts?

- name: Get image id
  command: >
    docker inspect -f '{% raw %}{{ .Image }}{% endraw %}' nginx
  register: container_image

- name: Do something with image
  command: echo {{ container_image.stdout }}

Michael DeHaan

unread,
Nov 17, 2014, 4:29:11 PM11/17/14
to ansible...@googlegroups.com
Sounds like there's a bug that should be filed - Can you please share the full ansible-playbook output from the above so we can see it in context though?

That message *may* be coming from Docker.





--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/54a84789-542a-4a09-92b5-d1baa7fdb979%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

simonq

unread,
Dec 3, 2014, 10:50:03 AM12/3/14
to ansible...@googlegroups.com
Sorry for the late reply, forgot about this one. Anyway, after looking through some commits it seems this error message comes with b61a785:

in lib/ansible/utils/template.py;

        except TemplateSyntaxError, e:
            raise errors.AnsibleError("template error while templating string: %s" % str(e))

Removing those lines makes the playbook run without errors :)

Michael DeHaan

unread,
Dec 3, 2014, 11:14:14 AM12/3/14
to ansible...@googlegroups.com
Removing the code that lets you know when there's a syntax error seems to be a bad thing :)

not sure what's up there to be honest, but I think pinning down what the error is is appropriate.



--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.

simonq

unread,
Dec 3, 2014, 1:49:27 PM12/3/14
to ansible...@googlegroups.com
So after putting some effort fixing the problem and doing some googling which led me to this thread I got it to work with the latest version.

Solution: change '{% raw %}{{ .Image }}{% endraw %}' to \{\{.Image\}\} 

I still would prefer using {% raw %} method since it looks nicer but at least it's working now :)

On Tuesday, 11 November 2014 22:58:23 UTC+1, simonq wrote:

ma...@moduscreate.com

unread,
Dec 5, 2014, 12:23:56 PM12/5/14
to ansible...@googlegroups.com
I'm having the same issue. Also with a docker inspect command. It's worth noting that the command with the raw tags executes correctly, and it's only when acting upon the stdout that the TemplateSyntaxError is raised.

Example:
https://gist.github.com/ateoto/758b4a1f16793270e608

This works under Ansible 1.7.2

Should I file a issue on GH?

Thanks,
Matt

Pavlo Baron

unread,
Feb 1, 2015, 5:49:52 AM2/1/15
to ansible...@googlegroups.com
I just had the same issue and solved it redirecting docker inspect output to a local file and cat'ing it from there. Is there a general fix for this meanwhile? Really looks like something is hanging around after docker inspect execution.
Reply all
Reply to author
Forward
0 new messages