# IP or DNS name of launched instances by ec2\_asg

**URL:** <https://forum.ansible.com/t/ip-or-dns-name-of-launched-instances-by-ec2-asg/17283>\
**Category:** Ansible Project\
**Created:** [January 15, 2015, 6:30pm UTC](https://forum.ansible.com/t/ip-or-dns-name-of-launched-instances-by-ec2-asg/17283 "2015-01-15T18:30:28Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![biswajit.banerjee](https://avatars.discourse-cdn.com/v4/letter/b/f08c70/32.png) [@biswajit.banerjee](https://forum.ansible.com/u/biswajit.banerjee)\
**Post date:** [January 15, 2015, 6:30pm UTC](https://forum.ansible.com/t/ip-or-dns-name-of-launched-instances-by-ec2-asg/17283/1 "2015-01-15T18:30:28Z")

</div>

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](http://www.commonfloor.com/mobile) and [app for residential communities](http://groups.commonfloor.com/mobile).

---

<div class="post-metadata">

**Author:** ![Ivan\_S\_Freitas](https://avatars.discourse-cdn.com/v4/letter/i/e99b99/32.png) [@Ivan\_S\_Freitas](https://forum.ansible.com/u/Ivan_S_Freitas)\
**Post date:** [January 15, 2015, 6:55pm UTC](https://forum.ansible.com/t/ip-or-dns-name-of-launched-instances-by-ec2-asg/17283/2 "2015-01-15T18:55:25Z")

</div>

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](http://docs.ansible.com/intro_dynamic_inventory.html#example-aws-ec2-external-inventory-script)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [January 17, 2015, 8:52am UTC](https://forum.ansible.com/t/ip-or-dns-name-of-launched-instances-by-ec2-asg/17283/3 "2015-01-17T08:52:31Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![biswajit.banerjee](https://avatars.discourse-cdn.com/v4/letter/b/f08c70/32.png) [@biswajit.banerjee](https://forum.ansible.com/u/biswajit.banerjee)\
**Post date:** [January 19, 2015, 12:18pm UTC](https://forum.ansible.com/t/ip-or-dns-name-of-launched-instances-by-ec2-asg/17283/4 "2015-01-19T12:18:33Z")

</div>

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](http://www.commonfloor.com/mobile) and [app for residential communities](http://groups.commonfloor.com/mobile).

---

<div class="post-metadata">

**Author:** ![Ivan\_S\_Freitas](https://avatars.discourse-cdn.com/v4/letter/i/e99b99/32.png) [@Ivan\_S\_Freitas](https://forum.ansible.com/u/Ivan_S_Freitas)\
**Post date:** [January 19, 2015, 4:43pm UTC](https://forum.ansible.com/t/ip-or-dns-name-of-launched-instances-by-ec2-asg/17283/5 "2015-01-19T16:43:18Z")

</div>

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).
