# failed\_when directive not working when task runs on multiple hosts

**URL:** <https://forum.ansible.com/t/failed-when-directive-not-working-when-task-runs-on-multiple-hosts/18921>\
**Category:** Ansible Project\
**Created:** [August 2, 2015, 7:31pm UTC](https://forum.ansible.com/t/failed-when-directive-not-working-when-task-runs-on-multiple-hosts/18921 "2015-08-02T19:31:17Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ard-Jan\_Barnas](https://avatars.discourse-cdn.com/v4/letter/a/a9adbd/32.png) [@Ard-Jan\_Barnas](https://forum.ansible.com/u/Ard-Jan_Barnas)\
**Post date:** [August 2, 2015, 7:31pm UTC](https://forum.ansible.com/t/failed-when-directive-not-working-when-task-runs-on-multiple-hosts/18921/1 "2015-08-02T19:31:17Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [August 3, 2015, 9:35pm UTC](https://forum.ansible.com/t/failed-when-directive-not-working-when-task-runs-on-multiple-hosts/18921/2 "2015-08-03T21:35:16Z")

</div>

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