# Changing actions in case a node fails

**URL:** <https://forum.ansible.com/t/changing-actions-in-case-a-node-fails/20269>\
**Category:** Ansible Project\
**Created:** [January 19, 2016, 9:33am UTC](https://forum.ansible.com/t/changing-actions-in-case-a-node-fails/20269 "2016-01-19T09:33:50Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![dcodix](https://avatars.discourse-cdn.com/v4/letter/d/f6c823/32.png) [@dcodix](https://forum.ansible.com/u/dcodix)\
**Post date:** [January 19, 2016, 9:33am UTC](https://forum.ansible.com/t/changing-actions-in-case-a-node-fails/20269/1 "2016-01-19T09:33:50Z")

</div>

Hi there,

I’ve been looking arround trying to find a way, with no luck.

When running a playbook against multiple nodes (say 5), and one of them fail a task (or block), I would like the other 4 nodes to run different tasks than the ones they would run if non of the nodes fail.

Is there any way to signal those nodes or to send them a variable which I could use to choose the actions to be taken?

The case of use is that if something fails in any host, I would like to “undo” what I have already done…

Thanks!

---

<div class="post-metadata">

**Author:** ![James\_Cammarata](https://avatars.discourse-cdn.com/v4/letter/j/7c8e57/32.png) [@James\_Cammarata](https://forum.ansible.com/u/James_Cammarata)\
**Post date:** [January 19, 2016, 1:48pm UTC](https://forum.ansible.com/t/changing-actions-in-case-a-node-fails/20269/2 "2016-01-19T13:48:11Z")

</div>

In 2.0.1, we’re going to allow the use of any\_errors\_fatal at the block level, so you can simply do this:

- block:

- task1: …

- task2: …  
…

- taskN: …

rescue:

- undo\_taskN: …  
…

- undo\_task2: …

- undo\_task1: …

any\_errors\_fatal: yes

However, there is currently a bug in 2.0.0.x where any\_errors\_fatal is not working as stated in the documentation, so you’ll have to wait until we get 2.0.1 out to do this.

---

<div class="post-metadata">

**Author:** ![dcodix](https://avatars.discourse-cdn.com/v4/letter/d/f6c823/32.png) [@dcodix](https://forum.ansible.com/u/dcodix)\
**Post date:** [January 19, 2016, 3:08pm UTC](https://forum.ansible.com/t/changing-actions-in-case-a-node-fails/20269/3 "2016-01-19T15:08:20Z")

</div>

Hi James,

This is a really nice feature! I was just trying to get there by using “delegate\_facts” which is not that clean of a solution,… 😉

Will this feature be in the “devel” branch soon?

And till now (with this new feature) was there any other way to achieve this?

Thank you very much!

---

<div class="post-metadata">

**Author:** ![James\_Cammarata](https://avatars.discourse-cdn.com/v4/letter/j/7c8e57/32.png) [@James\_Cammarata](https://forum.ansible.com/u/James_Cammarata)\
**Post date:** [January 19, 2016, 6:36pm UTC](https://forum.ansible.com/t/changing-actions-in-case-a-node-fails/20269/4 "2016-01-19T18:36:34Z")

</div>

This should be active in devel already, yes, and will be included in 2.0.1 as well.

---

<div class="post-metadata">

**Author:** ![dcodix](https://avatars.discourse-cdn.com/v4/letter/d/f6c823/32.png) [@dcodix](https://forum.ansible.com/u/dcodix)\
**Post date:** [January 20, 2016, 9:19am UTC](https://forum.ansible.com/t/changing-actions-in-case-a-node-fails/20269/5 "2016-01-20T09:19:53Z")

</div>

Hi James,

Yes it seems something is different regarding this on devel branch. But either I don’t understand what it does or something is not right.

In the current version (2.0.0.0) if I try to use “any\_errors\_fatal” in a block level it fails because this is not an option to be usable on a block.  
With the devel branch this changes. Now I can use this option but it doesn’t do what I was expecting.  
Now if one of the hosts fails, it make the rest fail and stop executing the playbook. But I am not able to have it execute the “rescue” part.

`

- name: deploy  
hosts: all  
gather\_facts: True  
tasks:
- block:
- file: path=/tmp/testfolder1 state=directory  
rescue:
- file: path=/tmp/testfolder2 state=directory  
any\_errors\_fatal: yes  
`

In this example, if I make it fail creating “/tmp/testfolder1”, it will not be creating “/tmp/testfolder2”.

Is this the way it is supposed to work? or should I open an issue on github?

Thanks!

---

<div class="post-metadata">

**Author:** ![James\_Cammarata](https://avatars.discourse-cdn.com/v4/letter/j/7c8e57/32.png) [@James\_Cammarata](https://forum.ansible.com/u/James_Cammarata)\
**Post date:** [January 20, 2016, 3:33pm UTC](https://forum.ansible.com/t/changing-actions-in-case-a-node-fails/20269/6 "2016-01-20T15:33:27Z")

</div>

Yes, please do.

---

<div class="post-metadata">

**Author:** ![dcodix](https://avatars.discourse-cdn.com/v4/letter/d/f6c823/32.png) [@dcodix](https://forum.ansible.com/u/dcodix)\
**Post date:** [January 21, 2016, 9:17am UTC](https://forum.ansible.com/t/changing-actions-in-case-a-node-fails/20269/7 "2016-01-21T09:17:31Z")

</div>

Hi there,

For anyone interest and to close this thread.  
I reported the bug and it is already solved!

[https://github.com/ansible/ansible/issues/14024](https://github.com/ansible/ansible/issues/14024)

Now In case of any host fail it will execute rescue to all of them! (devel branch only).

What a great feature!!!

Thanks James!
