Changing actions in case a node fails

83 views
Skip to first unread message

Dan C

unread,
Jan 19, 2016, 4:33:50 AM1/19/16
to Ansible Project
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!

James Cammarata

unread,
Jan 19, 2016, 8:48:17 AM1/19/16
to ansible...@googlegroups.com
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.


James Cammarata
Director, Ansible Core Engineering
github: jimi-c

--
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/2d3725bd-941a-440f-8d86-b85b8aa7f8c4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Dan C

unread,
Jan 19, 2016, 10:08:20 AM1/19/16
to Ansible Project
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!

James Cammarata

unread,
Jan 19, 2016, 1:36:41 PM1/19/16
to ansible...@googlegroups.com
This should be active in devel already, yes, and will be included in 2.0.1 as well.

James Cammarata
Director, Ansible Core Engineering
github: jimi-c

--
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.

Dan C

unread,
Jan 20, 2016, 4:19:53 AM1/20/16
to Ansible Project
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!




James Cammarata

unread,
Jan 20, 2016, 10:33:33 AM1/20/16
to ansible...@googlegroups.com
Yes, please do.

James Cammarata
Director, Ansible Core Engineering
github: jimi-c

--
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.

Dan C

unread,
Jan 21, 2016, 4:17:31 AM1/21/16
to Ansible Project
Hi there,

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


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

What a great feature!!!

Thanks James!


Reply all
Reply to author
Forward
0 new messages