# possible to use boto and ec2.py to return instance IDs instead of IP addresses?

**URL:** <https://forum.ansible.com/t/possible-to-use-boto-and-ec2-py-to-return-instance-ids-instead-of-ip-addresses/16680>\
**Category:** Ansible Project\
**Created:** [November 3, 2014, 11:59pm UTC](https://forum.ansible.com/t/possible-to-use-boto-and-ec2-py-to-return-instance-ids-instead-of-ip-addresses/16680 "2014-11-03T23:59:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Paul\_Stivers](https://avatars.discourse-cdn.com/v4/letter/p/b9e5f3/32.png) [@Paul\_Stivers](https://forum.ansible.com/u/Paul_Stivers)\
**Post date:** [November 3, 2014, 11:59pm UTC](https://forum.ansible.com/t/possible-to-use-boto-and-ec2-py-to-return-instance-ids-instead-of-ip-addresses/16680/1 "2014-11-03T23:59:42Z")

</div>

$ ansible --version

ansible 1.8 (develop 0179c13e04) last updated 2014/10/24 11:53:25 (GMT -700)

Right now I’m using “-i inventories/ec2.py -l 'tag\_Environment\_” to apply playbooks to servers in an environment, by IP address.

Now I have playbooks to stop and start all instances in an environment, but haven’t found a way to use ec2.py to apply these playbooks to all servers in the environment because stop and start needs a list of instance IDs rather than IP addresses. Is there a way? I’m thinking not, because ec2.py I don’t see instance\_id in the list of variables returned when run against a specific host.

If not, my intent is to write a script to use the cli to generate/regenerate a list of instance IDs for the instance\_ids variable.

Thanks for any help,

Paul

---

<div class="post-metadata">

**Author:** ![Wawrzek\_Niewodniczan](https://avatars.discourse-cdn.com/v4/letter/w/bbe5ce/32.png) [@Wawrzek\_Niewodniczan](https://forum.ansible.com/u/Wawrzek_Niewodniczan)\
**Post date:** [November 5, 2014, 11:02am UTC](https://forum.ansible.com/t/possible-to-use-boto-and-ec2-py-to-return-instance-ids-instead-of-ip-addresses/16680/2 "2014-11-05T11:02:30Z")

</div>

[...]

> Right now I'm using "-i inventories/ec2.py -l  
> 'tag\_Environment\_\<environment\>" to apply playbooks to servers in an  
> environment, by IP address.
> 
> Now I have playbooks to stop and start all instances in an environment, but  
> haven't found a way to use ec2.py to apply these playbooks to all servers  
> in the environment because stop and start needs a list of instance IDs  
> rather than IP addresses. Is there a way?

I'm not an export, but please check the ec2\_id variable. I think it's  
what you look for.

Cheers,  
Wawrzek

---

<div class="post-metadata">

**Author:** ![Paul\_Stivers](https://avatars.discourse-cdn.com/v4/letter/p/b9e5f3/32.png) [@Paul\_Stivers](https://forum.ansible.com/u/Paul_Stivers)\
**Post date:** [November 12, 2014, 11:00pm UTC](https://forum.ansible.com/t/possible-to-use-boto-and-ec2-py-to-return-instance-ids-instead-of-ip-addresses/16680/3 "2014-11-12T23:00:55Z")

</div>

Thanks, Wawrzek,

Also I’m seeing this in ec2.py. Makes me hopeful. Newb to Ansible and python so will take me a little while to figure out.

[https://raw.githubusercontent.com/ansible/ansible/devel/plugins/inventory/ec2.py](https://raw.githubusercontent.com/ansible/ansible/devel/plugins/inventory/ec2.py)

```auto
def __init__ (self):
        ''' Main execution path '''

        # Inventory grouped by instance IDs, tags, security groups, regions,
        # and availability zones
        self.inventory = self._empty_inventory()

        # Index of hostname (address) to instance ID
        self.index = {}

```

Paul
