# template error

**URL:** <https://forum.ansible.com/t/template-error/16753>\
**Category:** Ansible Project\
**Created:** [November 11, 2014, 9:58pm UTC](https://forum.ansible.com/t/template-error/16753 "2014-11-11T21:58:23Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![simonq](https://avatars.discourse-cdn.com/v4/letter/s/96bed5/32.png) [@simonq](https://forum.ansible.com/u/simonq)\
**Post date:** [November 11, 2014, 9:58pm UTC](https://forum.ansible.com/t/template-error/16753/1 "2014-11-11T21:58:23Z")

</div>

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 }}

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [November 17, 2014, 9:29pm UTC](https://forum.ansible.com/t/template-error/16753/2 "2014-11-17T21:29:08Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![simonq](https://avatars.discourse-cdn.com/v4/letter/s/96bed5/32.png) [@simonq](https://forum.ansible.com/u/simonq)\
**Post date:** [December 3, 2014, 3:50pm UTC](https://forum.ansible.com/t/template-error/16753/3 "2014-12-03T15:50:03Z")

</div>

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 🙂

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [December 3, 2014, 4:14pm UTC](https://forum.ansible.com/t/template-error/16753/4 "2014-12-03T16:14:09Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![simonq](https://avatars.discourse-cdn.com/v4/letter/s/96bed5/32.png) [@simonq](https://forum.ansible.com/u/simonq)\
**Post date:** [December 3, 2014, 6:49pm UTC](https://forum.ansible.com/t/template-error/16753/5 "2014-12-03T18:49:27Z")

</div>

So after putting some effort fixing the problem and doing some googling which led me to [this thread](https://www.mail-archive.com/ansible-project@googlegroups.com/msg07926.html) 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 🙂

---

<div class="post-metadata">

**Author:** ![matt2](https://avatars.discourse-cdn.com/v4/letter/m/c2a13f/32.png) [@matt2](https://forum.ansible.com/u/matt2)\
**Post date:** [December 5, 2014, 5:23pm UTC](https://forum.ansible.com/t/template-error/16753/6 "2014-12-05T17:23:56Z")

</div>

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](https://gist.github.com/ateoto/758b4a1f16793270e608)

This works under Ansible 1.7.2

Should I file a issue on GH?

Thanks,  
Matt

---

<div class="post-metadata">

**Author:** ![Pavlo\_Baron](https://avatars.discourse-cdn.com/v4/letter/p/aeb1de/32.png) [@Pavlo\_Baron](https://forum.ansible.com/u/Pavlo_Baron)\
**Post date:** [February 1, 2015, 10:49am UTC](https://forum.ansible.com/t/template-error/16753/7 "2015-02-01T10:49:52Z")

</div>

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.
