How to escape a variable?

I’m trying to execute the following task:

    - name: obtain image id
      local_action: shell docker inspect --format={{.Id}} {{ docker_image_name }} | cut  
      register: docker_image_id

where ‘{{.Id}}’ should not be considered as a variable. I’ve tried escaping it in this fashion: {{ ‘{{’ }} .Id {{ ‘}}’ }} as described by the Jinja2 docs, but that results in it appearing as ‘{# .Id #}’. I’m assuming that it’s still being considered as a variable.

Is there a way to force double curly brackets to not be considered as a variable?

Thanks.

Probably not the best way, but you could use a string inside of the
jinja templating

    - name: obtain image id
      local_action: shell docker inspect --format={{ '{{.Id}}' }} {{
docker_image_name }} | cut
      register: docker_image_id

Alternatively, you could also do:

{{.Id}}

Or

{% raw %}{{ .Id }}{% endraw %}

I probably prefer the raw/endraw most of the time.

I’m not entirely sure what I changed, but {{ ‘{{’ }} .Id {{ ‘}}’ }} started working for me.

Thanks for the alternatives, I’ll keep those in mind.

I also bumped into this, it is a rare corner-case when one tries to use double curly braces in a command… Which I was also trying with docker inspect, there are two better solutions for getting the data rather than executing a command:

1 - use the docker_containers variable which is automagically created on executing the docker module

2 - use the docker_facts module http://patg.net/ansible,docker/2014/07/10/ansible-docker-facts/

I prefer the second method because it’ll let me find the right container more easily.

Since I’m a curious person, I’d like to know if there’s a way to escape the double curly braces… because none of these methods worked for me on ansible 1.9.1