template error

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

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.

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 :slight_smile:

Removing the code that lets you know when there’s a syntax error seems to be a bad thing :slight_smile:

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

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 :slight_smile:

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

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.