failed_when directive not working when task runs on multiple hosts

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?

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}}"