# Looping / healthcheck urls / wait\_for\_uri

**URL:** <https://forum.ansible.com/t/looping-healthcheck-urls-wait-for-uri/12537>\
**Category:** Ansible Project\
**Created:** [March 20, 2013, 1:29am UTC](https://forum.ansible.com/t/looping-healthcheck-urls-wait-for-uri/12537 "2013-03-20T01:29:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![willthames](https://avatars.discourse-cdn.com/v4/letter/w/8dc957/32.png) [@willthames](https://forum.ansible.com/u/willthames)\
**Post date:** [March 20, 2013, 1:29am UTC](https://forum.ansible.com/t/looping-healthcheck-urls-wait-for-uri/12537/1 "2013-03-20T01:29:31Z")

</div>

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](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

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [March 20, 2013, 2:42am UTC](https://forum.ansible.com/t/looping-healthcheck-urls-wait-for-uri/12537/2 "2013-03-20T02:42:46Z")

</div>

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 🙂

---

<div class="post-metadata">

**Author:** ![fdavis](https://avatars.discourse-cdn.com/v4/letter/f/a698b9/32.png) [@fdavis](https://forum.ansible.com/u/fdavis)\
**Post date:** [March 22, 2013, 3:32am UTC](https://forum.ansible.com/t/looping-healthcheck-urls-wait-for-uri/12537/3 "2013-03-22T03:32:14Z")

</div>

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](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
