using failed_when: with changed_when:

304 views
Skip to first unread message

Mark Casey

unread,
Jan 15, 2015, 2:19:05 PM1/15/15
to ansible...@googlegroups.com
Hello list,

Do 'failed_when:' and 'changed_when:' effect one another?

(i.e. a failed task returns changed instead of failed because you'd specified both flags or vice versa?)

I guess I'm assuming that in any case 'failed' supersedes 'changed', and these flags just change the definition of those conditions and not their precedence(?).

Thank you,
Mark

Peter Mooshammer

unread,
Jan 15, 2015, 3:24:40 PM1/15/15
to ansible...@googlegroups.com
Well,

I just tried and tested both:

- name: run python script to make ip static
  script: ../files/gce_setip.py -a {{ item.public_ip }} -n {{ ipaddrname }} -z {{ zone }}
  register: res
  failed_when: "res.rc == 2"
  changed_when: "res.rc == 0"
  with_items: gce.instance_data
 
and it seems to work or at least I hope so ....

Mark Casey

unread,
Jan 18, 2015, 12:07:25 PM1/18/15
to ansible...@googlegroups.com
Thanks; I think I was a little vague, sorry. I'm actually already using them together to evaluate the return output of a script and determine what task state to return, and I wanted to just remove the 'failed_when:' line and let Ansible rely on the return code of the script being called instead of looking at the text it returns. But I wanted to leave the changed_when looking at the output.

I was initially (probably over-thinking it and) curious if there were any corner cases where that could effect if the task still used 'changed_when:' as I wanted it to, but having thought about it for a while I'm 99.9% sure that the only time my 'changed_when:' will get overridden is when the task actually fails according to the return code. And in that case I obviously would want the failed status to supersede whether or not the changed_when matched.

Mumshad Mannambeth

unread,
Nov 30, 2016, 4:18:55 PM11/30/16
to Ansible Project
I would like to set changed_when = not failed_when or vice versa. Is that possible?
Reply all
Reply to author
Forward
0 new messages