Running the a playbook to create an EC2 host, I find that there is a race condition for Ansible to be able to connect to the host.
Both wait_for
and shell: echo host_is_up
(with retry / do..until loop) tasks are not enough to avoid hitting the race condition where Ansible fails to SSH.
Running the play shows that the "Wait for SSH" task completes successfully, and the initial connect for the "Wait up to 10mins for potential cloud-init sshd race condition" task fails completely without retrying as I had expected:
$ export AWS_ACCESS_KEY_ID=ABCDEFGHIJKLMNOPQRST
$ export AWS_ACCESS_KEY=$AWS_ACCESS_KEY_ID
$ export AWS_SECRET_ACCESS_KEY=1234567890abcdefghijklmnopqrstuvwxyzABCD
$ export AWS_SECRET_KEY=$AWS_SECRET_ACCESS_KEY