failed_when directive not working when task runs on multiple hosts

30 views
Skip to first unread message

Ard-Jan Barnas

unread,
Aug 3, 2015, 12:58:34 PM8/3/15
to Ansible Project
Hello,

I am trying to figure out how to stop further execution of a playbook if only one of the hosts fails. My inventory contains two hosts assigned to the same group, so the playbook runs on both hosts. Considering I am standing up a failover cluster, I want the playbook to stop, and thus not continue on the second, non-failed host.

Here is an excerpt of one of the tasks in my playbook:

- name: configureQuorum
  script: configureQuorum.ps1
  register: result
  ignore_errors: true
  failed_when: ( result.rc != 0 )
 
The failed_when directive doesn't do the trick. Any ideas?


Brian Coca

unread,
Aug 3, 2015, 5:35:21 PM8/3/15
to Ansible Project
failure, success and changed are always per host, failed_when will
only determine when a particular host has failed.

What you want is a subsequent fail: directive

fail:
when: "{{'failed' in result}}"
> --
> You received this message because you are subscribed to the Google Groups
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to ansible-proje...@googlegroups.com.
> To post to this group, send email to ansible...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/2d5bbcba-842e-496b-9262-451f64da057d%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



--
Brian Coca
Reply all
Reply to author
Forward
0 new messages