Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"rescue" is not called if the failure of one host with "any_errors_fatal " option on block level #14024

Closed
dcodix opened this issue Jan 20, 2016 · 2 comments
Labels
bug This issue/PR relates to a bug.
Milestone

Comments

@dcodix
Copy link

dcodix commented Jan 20, 2016

Hi,

As seen on this thread:
https://groups.google.com/forum/#!topic/ansible-project/pUuPNPtuz9c

On the "devel" branch 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.

In the last "devel" version , yet if the option is accepted (in current 2.0.0 the option is just not accepted on block level) and all nodes are marked as failed the "rescue" part is not executed in any of them. Instead the execution just stops.

- name: anyname
  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 the previous example if the "/tmp/testfolder1" fails in any node, "/tmp/testfolder2" will not be created either, as rescue will not be executed.

Without the option "any_errors_fatal" (with a single host) the "rescue" part will be executed.

@jimi-c jimi-c added this to the stable-2.0 milestone Jan 20, 2016
@jimi-c jimi-c closed this as completed in ac89b0d Jan 20, 2016
@jimi-c
Copy link
Member

jimi-c commented Jan 20, 2016

Closing This Ticket

Hi!

We believe the above commit should resolve this problem for you. This will also be included in the next release.

If you continue seeing any problems related to this issue, or if you have any further questions, please let us know by stopping by one of the two mailing lists, as appropriate:

Because this project is very active, we're unlikely to see comments made on closed tickets, but the mailing list is a great way to ask questions, or post if you don't think this particular issue is resolved.

Thank you!

@jimi-c
Copy link
Member

jimi-c commented Jan 20, 2016

For the record, here's my test:

# cat inv 
h1 ansible_connection=local
h2 ansible_connection=local
h3 ansible_connection=local
h4 ansible_connection=local
h5 ansible_connection=local
# cat test.yml 
- hosts: all
  gather_facts: no
  tasks:
  - block:
    - fail:
      when: inventory_hostname == 'h3'
    rescue:
    - debug: msg="here we are in the rescue"
    any_errors_fatal: yes

When run:

# ansible-playbook -vvv test.yml -i inv 
Using /etc/ansible/ansible.cfg as config file
1 plays in test.yml
PLAY ***************************************************************************
TASK [fail] ********************************************************************
task path: /root/testing/14024/test.yml:5
skipping: [h2] => {"changed": false, "skip_reason": "Conditional check failed", "skipped": true}
fatal: [h3]: FAILED! => {"changed": false, "failed": true, "invocation": {"module_args": {}, "module_name": "fail"}, "msg": "Failed as requested from task"}
skipping: [h4] => {"changed": false, "skip_reason": "Conditional check failed", "skipped": true}
skipping: [h1] => {"changed": false, "skip_reason": "Conditional check failed", "skipped": true}
skipping: [h5] => {"changed": false, "skip_reason": "Conditional check failed", "skipped": true}
TASK [debug] *******************************************************************
task path: /root/testing/14024/test.yml:8
ok: [h1] => {
    "msg": "here we are in the rescue"
}
ok: [h2] => {
    "msg": "here we are in the rescue"
}
ok: [h3] => {
    "msg": "here we are in the rescue"
}
ok: [h4] => {
    "msg": "here we are in the rescue"
}
ok: [h5] => {
    "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=0   
h4                         : ok=1    changed=0    unreachable=0    failed=0   
h5                         : ok=1    changed=0    unreachable=0    failed=0   

@dcodix dcodix changed the title "rescue" is not called if the failure is inside an include "rescue" is not called if the failure of one host with "any_errors_fatal " option on block level Jan 21, 2016
jimi-c added a commit that referenced this issue Jan 21, 2016
Instead of bombing out of the strategy, we now properly mark hosts failed
so that the play iterator can handle block rescue/always properly.

Fixes #14024
@ansibot ansibot added bug This issue/PR relates to a bug. and removed bug_report labels Mar 7, 2018
@ansible ansible locked and limited conversation to collaborators Apr 25, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug This issue/PR relates to a bug.
Projects
None yet
Development

No branches or pull requests

3 participants