Changing actions in case a node fails

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!

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.

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,… :wink:

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!

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

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!

Yes, please do.

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

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

What a great feature!!!

Thanks James!