# wait\_for module questions

**URL:** <https://forum.ansible.com/t/wait-for-module-questions/12121>\
**Category:** Ansible Project\
**Created:** [December 6, 2012, 3:07am UTC](https://forum.ansible.com/t/wait-for-module-questions/12121 "2012-12-06T03:07:06Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Romeo\_Theriault](https://avatars.discourse-cdn.com/v4/letter/r/839c29/32.png) [@Romeo\_Theriault](https://forum.ansible.com/u/Romeo_Theriault)\
**Post date:** [December 6, 2012, 3:07am UTC](https://forum.ansible.com/t/wait-for-module-questions/12121/1 "2012-12-06T03:07:06Z")

</div>

I looked at the code and it doesn’t look like this is currently supported but thought I’d throw the question out there to see if there is some way to deal with this I’m not thinking of:

I’m trying to deploy some new version of a java webapp to a server, then start up the new app. (This is all scheduled from Jenkins.) What I’d like to do is use the wait\_for module to wait for it’s port to open up to verify that it’s up and listening. If the port fails to open within wait\_for’s delay timeout then proceed to rollback the app to the previous version.

Right now when the wait\_for modules’ delay is met the whole play exits. Is there some way to have it just continue and use the fact that the wait\_for delay failed to trigger the rollback tasks?

---

<div class="post-metadata">

**Author:** ![Romeo\_Theriault](https://avatars.discourse-cdn.com/v4/letter/r/839c29/32.png) [@Romeo\_Theriault](https://forum.ansible.com/u/Romeo_Theriault)\
**Post date:** [December 6, 2012, 3:09am UTC](https://forum.ansible.com/t/wait-for-module-questions/12121/2 "2012-12-06T03:09:53Z")

</div>

s/delay/timeout/g

---

<div class="post-metadata">

**Author:** ![Romeo\_Theriault](https://avatars.discourse-cdn.com/v4/letter/r/839c29/32.png) [@Romeo\_Theriault](https://forum.ansible.com/u/Romeo_Theriault)\
**Post date:** [December 6, 2012, 3:13am UTC](https://forum.ansible.com/t/wait-for-module-questions/12121/3 "2012-12-06T03:13:44Z")

</div>

Ok, I just found ‘ignore\_errors: True’ which answers half of my problem. Is there a way check if the wait\_for timeout was reached so the following tasks will only run if it was reached?

---

<div class="post-metadata">

**Author:** ![Jonathan1](https://avatars.discourse-cdn.com/v4/letter/j/f14d63/32.png) [@Jonathan1](https://forum.ansible.com/u/Jonathan1)\
**Post date:** [December 6, 2012, 6:33am UTC](https://forum.ansible.com/t/wait-for-module-questions/12121/4 "2012-12-06T06:33:13Z")

</div>

Romeo,

I am not 100% sure if this will work, as I am trying to implement a similar sort of thing myself as wel speak, but what you could do is try and use the register operator in the task where you are waiting, and then use that variable via an only\_if statement to conditionally execute some response to the failure.

- name: wait for service to start  
wait\_for: port=$port delay=10 timeout=120

register: this\_probably\_is\_going\_to\_break

This is ripping an idea from a playbook Dag Wieers posted

only\_if: “${post\_deployment\_test\_result.rc} != 0”

but you’ll need to use something besides the return code since you are not actually executing something.

---

<div class="post-metadata">

**Author:** ![Romeo\_Theriault](https://avatars.discourse-cdn.com/v4/letter/r/839c29/32.png) [@Romeo\_Theriault](https://forum.ansible.com/u/Romeo_Theriault)\
**Post date:** [December 6, 2012, 7:53am UTC](https://forum.ansible.com/t/wait-for-module-questions/12121/5 "2012-12-06T07:53:57Z")

</div>

Hi Jonathan, thanks for the response. I played a bit more with it and I agree I’ll probably need to use the register and some variation of only\_if. The trick is what variation 🙂 I’ll play with it some more tomorrow and see what I can find. Anyone know a good way to “see” what a register variable contains?

Thanks

---

<div class="post-metadata">

**Author:** ![Dag\_Wieers](https://avatars.discourse-cdn.com/v4/letter/d/45deac/32.png) [@Dag\_Wieers](https://forum.ansible.com/u/Dag_Wieers)\
**Post date:** [December 6, 2012, 9:31am UTC](https://forum.ansible.com/t/wait-for-module-questions/12121/6 "2012-12-06T09:31:14Z")

</div>

This is possible because the wait\_for plugin returns the time it waited (as elapsed). Beware though, the time waited is not the total time elapsed, but only the timeout portion (which I think is unfortunate)

Anyway, it would work like this:

---

<div class="post-metadata">

**Author:** ![Dag\_Wieers](https://avatars.discourse-cdn.com/v4/letter/d/45deac/32.png) [@Dag\_Wieers](https://forum.ansible.com/u/Dag_Wieers)\
**Post date:** [December 6, 2012, 10:12am UTC](https://forum.ansible.com/t/wait-for-module-questions/12121/7 "2012-12-06T10:12:19Z")

</div>

And now that I think of it, you can do the same without even using the elapsed time. Just by checking if wait\_for failed:

---

<div class="post-metadata">

**Author:** ![Romeo\_Theriault](https://avatars.discourse-cdn.com/v4/letter/r/839c29/32.png) [@Romeo\_Theriault](https://forum.ansible.com/u/Romeo_Theriault)\
**Post date:** [December 6, 2012, 8:38pm UTC](https://forum.ansible.com/t/wait-for-module-questions/12121/8 "2012-12-06T20:38:11Z")

</div>

This is beautiful. This is exactly what I was looking for. Thanks very much!
