-
Notifications
You must be signed in to change notification settings - Fork 23.7k
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
Ensure v2_playbook_on_no_hosts_remaining fires #81550
base: devel
Are you sure you want to change the base?
Conversation
Various tests failing with this, hard to tell if it's relevant:
|
8fa565b
to
722cc4c
Compare
722cc4c
to
6e3686e
Compare
Reproduced the test failure locally, should be able to work it out from here. |
6e3686e
to
fae7899
Compare
fae7899
to
45d9ce3
Compare
test/integration/targets/ansible-playbook-callbacks/all-callbacks.yml
Outdated
Show resolved
Hide resolved
Problems with rescue, looking into an alternative solution. |
The test
|
fb63bf1
to
15fd8c2
Compare
25c8339
to
8c11b0b
Compare
8c11b0b
to
2c35850
Compare
03e2f1a
to
7279698
Compare
7279698
to
fa82aad
Compare
Updated after conflicting change was made in the callbacks tests. |
@markgoddard the CI issues appear to be related to the patch in this PR. The same error output is present in different test runtimes: https://dev.azure.com/ansible/ansible/_build/results?buildId=102426&view=logs&j=b8b182ae-7382-5e2d-7321-805eb8f377b5&t=61efecb5-7da7-54db-c13c-3d39685f67a7&l=5606. |
Previously, v2_playbook_on_no_hosts_remaining would only fire with the linear strategy plugin if max_fail_percentage was used. This is because the 'result' in the linear strategy plugin's run() method was only changed from RUN_OK in the code path for max_fail_percentage. Prior to ansible#78680 it also fired when any_errors_fatal was used, but it no longer does. This change removes the 'result' variable since it is not really used any more. The main loop in the run() method exits at the correct points, and the StrategyModule.run() method on the base class correctly selects a return code based on the failed and unreachable hosts. The v2_playbook_on_no_hosts_remaining is now triggered outside of the main loop in StrategyModule.run(), based on the state of hosts in the play iterator. This seems to be a better source of truth than the Task Queue Manager's _failed_hosts list, which in some cases does not contain all failed hosts (I noticed this in the integration tests, which set ANSIBLE_FORCE_HANDLERS=true). There was also an issue in which v2_playbook_on_no_hosts_remaining would be triggered twice when using max_fail_percentage, and this has now been fixed. Fixes ansible#81549
Previously the v2_playbook_on_no_hosts_remaining callback did not fire when using the free strategy plugin. This is because the loop never satisfied the following condition when hosts fail or become unreachable: if len(hosts_left) == 0: This change moves the callback trigger outside of the main loop and uses the same condition as the linear strategy plugin to detect when there are no hosts remaining. Fixes ansible#81549
This change adds a new testcase to the ansible-playbook-callbacks integration test that checks the callbacks fired when all hosts fail. This provides a simple regression test for issue 81549.
fa82aad
to
55ed0b0
Compare
Thanks for spotting that, it seems the integration tests are a bit of a moving target. I've fixed up the expected output in the callback_default tests and CI looks happy again. |
Hi @webknjaz, how is it looking now? |
This plugin can be used to collect statistics about an Ansible run and write them to a file in JSON format. The statistics currently include the count and names of failed and unreachable hosts. They also include whether execution stopped due to a lack of remaining hosts. This last signal can be helpful if trying to determine whether Ansible completed successfully for some but not all hosts, e.g. when attempting to handle unreachable hosts. Unfortunately the v2_playbook_on_no_hosts_remaining callback is not reliably fired, as outlined in [1]. A fix for this has been proposed in [2]. [1] ansible/ansible#81549 [2] ansible/ansible#81550 Change-Id: I6eedc23726f47e88b50efbaa80db33965aa58e1a
This plugin can be used to collect statistics about an Ansible run and write them to a file in JSON format. The statistics currently include the count and names of failed and unreachable hosts. They also include whether execution stopped due to a lack of remaining hosts. This last signal can be helpful if trying to determine whether Ansible completed successfully for some but not all hosts, e.g. when attempting to handle unreachable hosts. Unfortunately the v2_playbook_on_no_hosts_remaining callback is not reliably fired, as outlined in [1]. A fix for this has been proposed in [2]. [1] ansible/ansible#81549 [2] ansible/ansible#81550 Change-Id: I6eedc23726f47e88b50efbaa80db33965aa58e1a
This plugin can be used to collect statistics about an Ansible run and write them to a file in JSON format. The statistics currently include the count and names of failed and unreachable hosts. They also include whether execution stopped due to a lack of remaining hosts. This last signal can be helpful if trying to determine whether Ansible completed successfully for some but not all hosts, e.g. when attempting to handle unreachable hosts. Unfortunately the v2_playbook_on_no_hosts_remaining callback is not reliably fired, as outlined in [1]. A fix for this has been proposed in [2]. [1] ansible/ansible#81549 [2] ansible/ansible#81550 Change-Id: I6eedc23726f47e88b50efbaa80db33965aa58e1a
This plugin can be used to collect statistics about an Ansible run and write them to a file in JSON format. The statistics currently include the count and names of failed and unreachable hosts. They also include whether execution stopped due to a lack of remaining hosts. This last signal can be helpful if trying to determine whether Ansible completed successfully for some but not all hosts, e.g. when attempting to handle unreachable hosts. Unfortunately the v2_playbook_on_no_hosts_remaining callback is not reliably fired, as outlined in [1]. A fix for this has been proposed in [2]. Flake8 error E402 (module level import not at top of file) is ignored because it is incompatible with Ansible sanity checks for plugins. [1] ansible/ansible#81549 [2] ansible/ansible#81550 Change-Id: I6eedc23726f47e88b50efbaa80db33965aa58e1a
Thank you for your contribution. Apologies this hasn't had much attention. For this particular change, during the triage meeting the core team agreed that this requires more discussion and research as to what was the original intent behind the
There are still a lot of open issues (and PRs) to work on. It's just some (like this one) require more time to review and when they do prioritisation gets in the way. Thank you for understanding. |
Thank you for responding. I'm glad to hear it's on the core team's radar. For context, I'd like to use the callback to determine whether ansible execution reached the end or was terminated prematurely. This would allow me to know when a run had some "acceptable" number of failed or unreachable hosts, and will potentially be used in combination with max_fail_percentage. |
There are various cases where the
v2_playbook_on_no_hosts_remaining
callback does not fire in both the free and linear strategy plugins. This PR fixes those issues, as well as removing a duplicate call to the same callback when usingmax_fail_percentage
.Fixes: #81549