using failed_when in a with_ loop

886 views
Skip to first unread message

Serge van Ginderachter

unread,
Nov 11, 2013, 12:45:45 PM11/11/13
to ansible...@googlegroups.com
Dear List,

I'm looking into implementing a kind of application health check after deployment. My applications are defined per cluster group with a complex var of following kind:

apps:
- port: 8080
  path: /app
  monitors:
  - get: /app/healthcheck
    receive: Status up
  - ...
- ...

I already use this to configure checks on the load-balancer, and now want to also use the same data to check it after my ansible deploy playbooks.

I can easily run something like
- task: check
  module: uri ... ->  item.1.get
  with_subelements:
  - apps
  - monitors

But ideally I'd like to add a failed_when: and check that item.1.receive is found in the uri's returned content string. But that's not possible, as failed_when doesn't work on the separate iterations of the loop, only the consolidated task. What would be the best option to solve this? Right now, I can think of the following options, which need a code update:

- somehow update ansible to (optionally) allow to have failed_when work on the separate iterations
- register the task, then make the check in a separate task - but this cannot work in current ansible, as I would need to loop through the same subelements *and* the previously registered variable (this is however another use case for nesting lookup plugins as per my PR #4627)
- extend the uri plugin to succeed or fail not only on the return_code, but also optionally on a given string to be found in the returned content.

Which of these options are acceptable?
Does anyone see another option, maybe one that can be implemented with the current ansible code base?

Thanks,

Serge

Michael DeHaan

unread,
Nov 12, 2013, 10:54:07 AM11/12/13
to ansible...@googlegroups.com
I don't like the idea of having two ways that failed_when works as that seems confusing to me.

As you just have two tasks here, I'd probably just split these things up into two explicit tasks for now.

 
Reply all
Reply to author
Forward
0 new messages