# gather tag name about instance

**URL:** <https://forum.ansible.com/t/gather-tag-name-about-instance/20390>\
**Category:** Ansible Project\
**Created:** [January 29, 2016, 11:40pm UTC](https://forum.ansible.com/t/gather-tag-name-about-instance/20390 "2016-01-29T23:40:32Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Colin\_Byrne](https://avatars.discourse-cdn.com/v4/letter/c/ecd19e/32.png) [@Colin\_Byrne](https://forum.ansible.com/u/Colin_Byrne)\
**Post date:** [January 29, 2016, 11:40pm UTC](https://forum.ansible.com/t/gather-tag-name-about-instance/20390/1 "2016-01-29T23:40:32Z")

</div>

Hey,

So I want to access the tag name I set at initial ec2 creation to use it as my hostname throughout the server. To set the tag\_name, I use a dictionary / sub\_list as such:

`

server\_group\_settings:  
integ:  
security\_groups: [‘sg-81398ee4’, ‘sg-a6398ec3’]  
image: ami-06116566  
instance\_type: t2.medium #needs to match the base image size  
region: us-west-1  
key\_name: ansible\_provisioning  
termination\_protection: yes  
subnet\_id: subnet-819f7cd8

server\_groups:

- type: integ  
servers:
- { name: integ-bob, private\_ip: 10.101.1.182 }
- { name: staging-steve, private\_ip: 10.101.1.30 }
- { name: staging-mike, private\_ip: 10.101.1.31 }  
prod:
- { name: staging-joey, private\_ip: 10.101.1.34 }

`

Once the server has been created, I want to be able to access the tag\_name by gathering facts about the remote sever and pulling down the tag name. Unfortunately, I cannot connect with the hosts through a dynamic inventory, due to them being with a VPC. They do show up in the ec2.py --list, so if I were able to somehow register the results of ‘ec2.py --list’ as a variable, I would be able to find the tag\_name by using the ip, which I can get through ec2\_facts (or a couple other modules, I believe).

Unfortunately with the way I nest the server\_groups dictionary (which is the only way i could get nesting so deep to work), the server name is not nested below the private ip.

What is the best way to do this? should I keep a second list (very redundant) with the server name nested below? Here is my ec2 playbook:

`
