any_errors_fatal is not working as expected with block/rescue

16 views
Skip to first unread message

karim okasha

unread,
Nov 22, 2018, 2:21:56 PM11/22/18
to Ansible Project

the option "any_errors_fatal" on a block level should (if a single node fails) have all nodes to fail and then execute "rescue" in all nodes.

However, as per my testing I can see that that the rescue block is only executed on the failed node only not in all nodes. I think that the proper behaviour should be that the resuce block is executed on all the nodes in order to implement a rollback behaviour.

This issue has been raised before as per this thread and i should be working since ansible 2.0 but with Ansible 2.7 that i am testing with this is not happening.

The playbook and output is as shown below

inventroy:
h1 ansible_connection=local
h2 ansible_connection=local
h3 ansible_connection=local
h4 ansible_connection=local
h5 ansible_connection=local

Playbook:

---
- hosts: all
gather_facts: no
tasks:
- block:
- fail:
when: inventory_hostname == 'h3'
rescue:
- name: Save By Rescue
debug: msg="here we are in the rescue"
any_errors_fatal: yes


Play output

PLAY [all] ************************************************************************************************************************************

TASK [fail] ***********************************************************************************************************************************
skipping: [h1]
skipping: [h2]
fatal: [h3]: FAILED! => {"changed": false, "msg": "Failed as requested from task"}
skipping: [h4]
skipping: [h5]

TASK [Chenc another Task] *********************************************************************************************************************
ok: [h1] => {
    "msg": "Another Task"
}
ok: [h2] => {
    "msg": "Another Task"
}
ok: [h4] => {
    "msg": "Another Task"
}
ok: [h5] => {
    "msg": "Another Task"
}

TASK [Save By Rescue] *************************************************************************************************************************
ok: [h3] => {
    "msg": "here we are in the rescue"
}

PLAY RECAP ************************************************************************************************************************************
h1                         : ok=1    changed=0    unreachable=0    failed=0
h2                         : ok=1    changed=0    unreachable=0    failed=0
h3                         : ok=1    changed=0    unreachable=0    failed=1
h4                         : ok=1    changed=0    unreachable=0    failed=0
h5                         : ok=1    changed=0    unreachable=0    failed=0







Reply all
Reply to author
Forward
0 new messages