Looping / healthcheck urls / wait_for_uri

After a server is started, I would like to wait for a specific response from a web healthcheck before continuing.

wait_for is great for waiting for a port to be opened, and uri would be useful for performing the healthcheck, but there’s no obvious way to combine them or just loop e.g.

name: await healthcheck
local_action: uri url=http://host:port/healthcheck return_content=yes
register: healthcheck
until: delay=30 ${healthcheck.content} == “yes”

Any suggestions on how to achieve this ? Or should I just write my own wait_for_uri plugin?

Will

An "until" has definitely been proposed. I have some concerns about
making until be based on a python style eval based since conditionals
using only_if are already rather unpopular compared to the "when"
variants, though I can't say I know a better way to do it.

It would end up looking like so, the way you've written it.

until: delay=30 test='"${healthcheck.content}" == "yes"'

We could perhaps make a series of "until_" variants like the "when_"
ones though.

Syntax is important, so let's see who can come up with something
cleaner than that :slight_smile:

I’ve used the shell module using a bash ‘until’ loop a few times.
I think it would be most generalized if we could check any part of the json result.

What if until assumes that any key value pairs it gets are tests,
except for a few specific ones with an until, or maybe ‘u’ for short, prefix.
(used until parameters like timeout, number of tries, or sleep time inbetween attempts)

To reuse the example:

  • name: await healthcheck
    local_action: uri url=http://host:port/healthcheck return_content=yes
    until_string: udelay=30 content==yes

Or my own example, waiting for a kvm domain to shut off:

  • command: virsh domstate myvm
    until_string: utimeout=120 usleep=10 stdout=“shut off”

Or waiting for the X to stop:

  • command: pidof Xorg
    until_int: rc=1