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
“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.
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
`
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?
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
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.