# Waiting for Elastic IP address?

**URL:** <https://forum.ansible.com/t/waiting-for-elastic-ip-address/15558>\
**Category:** Ansible Project\
**Created:** [June 26, 2014, 8:22pm UTC](https://forum.ansible.com/t/waiting-for-elastic-ip-address/15558 "2014-06-26T20:22:57Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jason\_Levitt](https://avatars.discourse-cdn.com/v4/letter/j/779978/32.png) [@Jason\_Levitt](https://forum.ansible.com/u/Jason_Levitt)\
**Post date:** [June 26, 2014, 8:22pm UTC](https://forum.ansible.com/t/waiting-for-elastic-ip-address/15558/1 "2014-06-26T20:22:57Z")

</div>

Does anyone have an example of waiting for an Elastic IP address to  
become “ready” to access? Apparently, waiting for state=started and  
port 22 to become accessible (see below) is not sufficient. The  
next step after this usually fails because the Elastic IP isn’t ready yet.

J

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [June 27, 2014, 12:43pm UTC](https://forum.ansible.com/t/waiting-for-elastic-ip-address/15558/2 "2014-06-27T12:43:31Z")

</div>

“Apparently, waiting for state=started and  
port 22 to become accessible (see below) is not sufficient.”

Almost always, it’s useful to put a “pause” after waiting for port 22 to become open. The reason for this is SSH isn’t always ready as soon as the port is up - usually it’s not. a 5 second pause module call after the wait\_for takes care of it.

---

<div class="post-metadata">

**Author:** ![Jason\_Levitt](https://avatars.discourse-cdn.com/v4/letter/j/779978/32.png) [@Jason\_Levitt](https://forum.ansible.com/u/Jason_Levitt)\
**Post date:** [June 27, 2014, 3:29pm UTC](https://forum.ansible.com/t/waiting-for-elastic-ip-address/15558/3 "2014-06-27T15:29:58Z")

</div>

It’s still not working. I even made the pause 10 seconds (see below). SSH still doesn’t work  
until maybe 30 seconds later. I’m launching an m3large instance and I’m only  
using the Amazon Linux base (no customization). AMI: ami-7c807d14

Any ideas?

J

`

- name: Tie elastic IP to the instance  
ec2\_eip: instance\_id={{ item }} region={{ region }} public\_ip={{ my\_elastic\_ip }}  
with\_items: ec2\_info.instance\_ids

- name: wait for instances to listen on port:22  
wait\_for: timeout=480 state=started host={{ my\_elastic\_ip }} port=22

- pause: seconds=10  
`

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [June 27, 2014, 3:45pm UTC](https://forum.ansible.com/t/waiting-for-elastic-ip-address/15558/4 "2014-06-27T15:45:45Z")

</div>

Perhaps it’s taking longer because an EIP is involved, apologies as my previous info-sharing was based on general SSH experiments.

Could it be that the EIP itself is not yet ready?

---

<div class="post-metadata">

**Author:** ![Jason\_Levitt](https://avatars.discourse-cdn.com/v4/letter/j/779978/32.png) [@Jason\_Levitt](https://forum.ansible.com/u/Jason_Levitt)\
**Post date:** [June 27, 2014, 4:06pm UTC](https://forum.ansible.com/t/waiting-for-elastic-ip-address/15558/5 "2014-06-27T16:06:55Z")

</div>

Quite probably it’s the EIP since it worked ok before I added it. On the documentation page for

the ansible ec2-eip module, it says:

`"There may be a delay between the time the Elastic IP is assigned and when the cloud instance is reachable via the new address. Use wait_for and pause to delay further playbook execution until the instance is reachable, if necessary."`

However, there is no example provided for how to do this with the ec2-eip module.  
So, I’m wondering how to specifically wait for an EIP to be “ready”.  
It seems to me that this should work for both the elastic ip and port 22, but it doesn’t even though it executes without error:

`

- name: wait for instances to listen on port:22  
wait\_for: timeout=480 state=started host={{ my\_elastic\_ip }} port=22  
`

J

---

<div class="post-metadata">

**Author:** ![Michael\_Blakeley](https://avatars.discourse-cdn.com/v4/letter/m/35a633/32.png) [@Michael\_Blakeley](https://forum.ansible.com/u/Michael_Blakeley)\
**Post date:** [March 11, 2015, 4:20am UTC](https://forum.ansible.com/t/waiting-for-elastic-ip-address/15558/6 "2015-03-11T04:20:39Z")

</div>

I find this works well:

- pause: seconds=15
- name: wait for ssh  
wait\_for: port=22 timeout=600

Without the pause, I find that wait\_for alone often fails. Pausing less than 15 seconds usually fails, too.
