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
any_errors_fatal is not working as expected with block/rescue #49041
Comments
Hi @kokasha, thank you for submitting this issue! |
Files identified in the description: If these files are inaccurate, please update the |
@kokasha In any case your expectation does not match our intended feature.
The behaviour you are looking for can be done with a |
@bcoca Can you please illustrate more what is the expected behavior that we should see? The behavior that i was expecting is some sort of a rollback behavior (i run a task/tasks inside the block on a number of hosts) and if this task fails on any host i should run the rescue task on All the hosts in order to rollback all the changes that was implemented in the block tasks. Also in a previous issue that was raised #14024, this behavior this possible and was implemented, so why this is not working at the moment. Finally, can you please with any simple playbook how to implement this rollback behavior using fail or assert as mentioned in your reply? Thanks a lot for your support and feedback |
What i expect from your playbook:
The ticket you point at had As for the example, you should really try IRC or the mailing lists, but here it is anyways: - hosts: all
gather_facts: no
tasks:
- block:
- fail:
when: inventory_hostname == 'mailer1'
register: myfail
- name: fail if any host failed previous task
fail:
when: (hostvars.values()|selectattr('myfail', 'failed')|list)|length > 0
rescue:
- name: Save By Rescue
debug: msg="here we are in the rescue"
|
FYI, this is clearly documented: |
Possible MisunderstandingHi! Thanks very much for your submission to Ansible. It sincerely means a lot to us. We believe the ticket you have filed is being somewhat misunderstood, as one thing works a little differently than stated. As stated in the link above, this is expected behaviour. In the future, this might be a topic more well suited for the user list, which you can also post here if you'd like some more help with the above. Thank you once again for this and your interest in Ansible! |
Closing as per above. |
SUMMARY
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. There was a previous discussion regarding this same issue (#14024) and it should be fixed since release 2.0, however, testing with release 2.7.2 i can see that the behavior is not as expected.
ISSUE TYPE
COMPONENT NAME
any_errors_fatal with block/rescue
ANSIBLE VERSION
CONFIGURATION
OS / ENVIRONMENT
This is a behavior for ansible execution irrelevant to the target OS.
STEPS TO REPRODUCE
Minimal Test Case
Inventory:
h1 ansible_connection=local
h2 ansible_connection=local
h3 ansible_connection=local
h4 ansible_connection=local
h5 ansible_connection=local
EXPECTED RESULTS
The expected result is the rescue block will run on all nodes not only the failed one (since we are using any_errors_fatal=yes)
ACTUAL RESULTS
The rescue block is only executed for the failed host not all the hosts
The text was updated successfully, but these errors were encountered: