wait_for module questions

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?

s/delay/timeout/g

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?

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.

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 :slight_smile: 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

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:

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:

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