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

60 views
Skip to first unread message

Paul Stivers

unread,
Nov 3, 2014, 6:59:42 PM11/3/14
to ansible...@googlegroups.com

$ 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_<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

Wawrzek Niewodniczanski

unread,
Nov 5, 2014, 6:02:54 AM11/5/14
to ansible...@googlegroups.com
On 3 November 2014 23:59, Paul Stivers <psti...@gmail.com> wrote:
[...]
> 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
--
Dr Wawrzyniec Niewodniczański or Wawrzek for short
PhD in Quantum Chemistry & MSc in Molecular Engineering
WWW: http://wawrzek.name E-MAIL: jo...@wawrzek.name
Linux User #177124

Paul Stivers

unread,
Nov 12, 2014, 6:00:56 PM11/12/14
to ansible...@googlegroups.com
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

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


Reply all
Reply to author
Forward
0 new messages