# How to escape a variable?

**URL:** <https://forum.ansible.com/t/how-to-escape-a-variable/15893>\
**Category:** Ansible Project\
**Created:** [August 8, 2014, 5:04pm UTC](https://forum.ansible.com/t/how-to-escape-a-variable/15893 "2014-08-08T17:04:32Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vijay\_Korapaty](https://avatars.discourse-cdn.com/v4/letter/v/5f9b8f/32.png) [@Vijay\_Korapaty](https://forum.ansible.com/u/Vijay_Korapaty)\
**Post date:** [August 8, 2014, 5:04pm UTC](https://forum.ansible.com/t/how-to-escape-a-variable/15893/1 "2014-08-08T17:04:32Z")

</div>

I’m trying to execute the following task:

```auto
    - name: obtain image id

```

```auto
      local_action: shell docker inspect --format={{.Id}} {{ docker_image_name }} | cut  

```

```auto
      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](http://jinja.pocoo.org/docs/templates/#escaping), 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.

---

<div class="post-metadata">

**Author:** ![Michael\_Peters](https://avatars.discourse-cdn.com/v4/letter/m/c2a13f/32.png) [@Michael\_Peters](https://forum.ansible.com/u/Michael_Peters)\
**Post date:** [August 8, 2014, 9:35pm UTC](https://forum.ansible.com/t/how-to-escape-a-variable/15893/2 "2014-08-08T21:35:50Z")

</div>

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

&nbsp;&nbsp;&nbsp;&nbsp;- name: obtain image id  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;local\_action: shell docker inspect --format={{ '{{.Id}}' }} {{  
docker\_image\_name }} | cut  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;register: docker\_image\_id

---

<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:** [August 8, 2014, 11:32pm UTC](https://forum.ansible.com/t/how-to-escape-a-variable/15893/3 "2014-08-08T23:32:43Z")

</div>

Alternatively, you could also do:

{{.Id}}

Or

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

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

---

<div class="post-metadata">

**Author:** ![Vijay\_Korapaty](https://avatars.discourse-cdn.com/v4/letter/v/5f9b8f/32.png) [@Vijay\_Korapaty](https://forum.ansible.com/u/Vijay_Korapaty)\
**Post date:** [August 9, 2014, 1:24am UTC](https://forum.ansible.com/t/how-to-escape-a-variable/15893/4 "2014-08-09T01:24:12Z")

</div>

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

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

---

<div class="post-metadata">

**Author:** ![Conrado\_Buhrer](https://avatars.discourse-cdn.com/v4/letter/c/ccd318/32.png) [@Conrado\_Buhrer](https://forum.ansible.com/u/Conrado_Buhrer)\
**Post date:** [May 19, 2015, 7:26pm UTC](https://forum.ansible.com/t/how-to-escape-a-variable/15893/5 "2015-05-19T19:26:20Z")

</div>

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/](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
