IP or DNS name of launched instances by ec2_asg

Hi,

After instance launched using ec2_asg , I wish to add newly created instance to ansible control machin’s host group.
I need to get the public ip and public dns of launched instances.

I wonder , if registering the ec2_asg output to a list , say asg_result and then getting the ip (item.public_ip) as asg_result.instances will work ?

Please let me know the best practices for the same .

Regards,
Biswajit

Using a smartphone? Try our app for property search and app for residential communities.

Have you considered using the ec2 dynamic inventory plugin with tags?
Instead of adding the public ip's to the inventory, ansible can return a
list of them of the machines with a given tag. See [1] for the
documentation about it. It can also return the ip's based on other
information, such as security groups, etc.

[1]: http://docs.ansible.com/intro_dynamic_inventory.html#example-aws-ec2-external-inventory-script

Hi Biswajit,

can you please paste the output of the “asg_result” and i’ll try to help you that how you can add the ip to the hosts file.

@Ivan, he also give you really good suggestion but if you want to register the ip address then please paste the output of the “asg_result”. Thanks

Thank you Evan and Arbab.

My use case here, as soon as autoscale take place and new instance are UP…I have few more plays to start …like for an example …installing and configuring git …apache…other needed settings… so those role should identify the newly launched
instances. So need a mechanism for that.

Please note :All these play/roles is part of a same playbook.

Using a smartphone? Try our app for property search and app for residential communities.

If what you're executing in the servers has no side-effects and your
plays are properly configured to be indempotent, it shouldn't matter
if the machine is a fresh instance or an "old" one; running ansible in
each one of them should make them consistent between themselves (i.e.,
install everything needed in a fresh instance and keeping every other
instance unchanged).