# dyanamic ec2 instance

**URL:** <https://forum.ansible.com/t/dyanamic-ec2-instance/28200>\
**Category:** Ansible Project\
**Created:** [July 30, 2018, 6:10pm UTC](https://forum.ansible.com/t/dyanamic-ec2-instance/28200 "2018-07-30T18:10:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dmukeshsai](https://avatars.discourse-cdn.com/v4/letter/d/a88e57/32.png) [@dmukeshsai](https://forum.ansible.com/u/dmukeshsai)\
**Post date:** [July 30, 2018, 6:10pm UTC](https://forum.ansible.com/t/dyanamic-ec2-instance/28200/1 "2018-07-30T18:10:10Z")

</div>

hi,

i want to launch ec2 instance and automate the install jenkins on that instance through playbook.

i tried but it throws the exception,when ever we launch instance dynamic ip is generated,how do we give host name,task is launch instance and when ever instance is laaunched i want jenkins on that instance through one playbook.

thanks.

---

<div class="post-metadata">

**Author:** ![Tchia04](https://avatars.discourse-cdn.com/v4/letter/t/fbc32d/32.png) [@Tchia04](https://forum.ansible.com/u/Tchia04)\
**Post date:** [July 31, 2018, 5:39am UTC](https://forum.ansible.com/t/dyanamic-ec2-instance/28200/2 "2018-07-31T05:39:02Z")

</div>

So you probably want to do this in two plays in a playbook  
first play targetting localhost and create the ec2 instance with ec2 module  
then use the add\_host module to add the ip address that was created into a group

2nd play targetting the new group with the ip address of the ec2 you created in the first play and install jenkins

An example is shown at  
[http://docs.catalystcloud.io/tutorials/ansible-create-x-servers-using-in-memory-inventory.html](http://docs.catalystcloud.io/tutorials/ansible-create-x-servers-using-in-memory-inventory.html)

Tony Chia
