# How to get ec2 instance id tag when it's in an autoscaling group - a Jinja2 escaping problem?

**URL:** <https://forum.ansible.com/t/how-to-get-ec2-instance-id-tag-when-its-in-an-autoscaling-group-a-jinja2-escaping-problem/17762>\
**Category:** Ansible Project\
**Tags:** aws\
**Created:** [March 17, 2015, 9:16am UTC](https://forum.ansible.com/t/how-to-get-ec2-instance-id-tag-when-its-in-an-autoscaling-group-a-jinja2-escaping-problem/17762 "2015-03-17T09:16:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Stephen\_Tan](https://avatars.discourse-cdn.com/v4/letter/s/f17d59/32.png) [@Stephen\_Tan](https://forum.ansible.com/u/Stephen_Tan)\
**Post date:** [March 17, 2015, 9:16am UTC](https://forum.ansible.com/t/how-to-get-ec2-instance-id-tag-when-its-in-an-autoscaling-group-a-jinja2-escaping-problem/17762/1 "2015-03-17T09:16:48Z")

</div>

Sounds simple, but it isn’t.

I want to create a variable called “instance\_role” which is set to the aws:autoscaling:groupName on the instance.  
However, there is a formatting problem as the colons are used by Jinja and I can’t figure out how to escape them.

The role:

`

---

<div class="post-metadata">

**Author:** ![Stephen\_Tan](https://avatars.discourse-cdn.com/v4/letter/s/f17d59/32.png) [@Stephen\_Tan](https://forum.ansible.com/u/Stephen_Tan)\
**Post date:** [March 17, 2015, 11:56am UTC](https://forum.ansible.com/t/how-to-get-ec2-instance-id-tag-when-its-in-an-autoscaling-group-a-jinja2-escaping-problem/17762/2 "2015-03-17T11:56:30Z")

</div>

OK - someone called halberom on freenode #ansible gave me the answer:

`

# A better way of referencing dict elements to avoid escaping issues

instance\_role: “{{ instance\_tags[‘tags’][‘aws:autoscaling:groupName’] }}”

`

this is a cleaner way of getting to the dictionary.
