Retrying a command until a JSON response contains a specific key

Hi,

I have somewhat of an edge-case I just have no idea how to properly handle using Ansible.

In a playbook, I’m provisioning an AWS Elasticsearch domain, an asynchronous task. On AWS, booting the cluster takes a few minutes, so meanwhile I’m free to provision other stuff (EC2, RDS, etc.) At some point though, I must know what the URL (endpoint) of the Elasticsearch cluster is, so that I can register it and move forward with the playbook. Getting this info is easy, just an aws-cli command away: aws es describe-elasticsearch-domain–domain-name my-es-domain.

Now, by the time the command is issued, the cluster might not be ready. The JSON response will tell me, if the DomainStatus.Endpoint key is missing then the cluster is not up and running and I should wait until it becomes available.

So essentially, I’m trying to find the best way to emulate a “wait_for” behavior but for a JSON payload. Checking the JSON response and retrying the command on a regular basis until the expected key is available. Any insights?

Thank you!