best way to wait for AWS metadata to resolve?

I’m not sure whether this is something ansible can do out of the box or not.

I am looking for a way to pause execution of a playbook until certain pieces of metadata become available from AWS.

Basically I’m starting an ec2 instance inside a firewalled VPC in AWS and when it’s ready it sets a few tag values.

I’d like to be able to construct tasks that spin up this ec2 instance, wait until it sees those tags are available (or times out), and then continue.

Is this possible using the standard ansible toolkit, or am I (a) going about this all wrong, or (b) going to need to reach for a custom coded module?

There’s a wait option on ec2 instance creation that will stop the playbook until the instance is up. Not sure what exactly it is testing, but I’ve seen it there.

A primitive alternative is just to stick a one-minute (or whatever is needed) delay into the playbook.

You can also put a delay loop in. See this link and seach for “Retrying”:

https://docs.ansible.com/ansible/latest/user_guide/playbooks_loops.html

Regards, K.

The wait option checks if the instance id already exists:

https://github.com/ansible/ansible/blob/devel/lib/ansible/modules/cloud/amazon/ec2.py#L1234-L1240

I guess this is "the right thing".

Thanks folks,

The ‘wait: true’ option is one I have already put into the role, but it is returning before the boot-up sequence has completed.

I think what I’ll try to do is move the logic for waiting into the boot-up scripts themselves, so that I can spin them all up at once and have then wait on the primary to serve up the metadata needed.