gather tag name about instance

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:

`