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

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:

`

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.