Open ClausHolbechArista opened 5 months ago
Files identified in the description:
If these files are incorrect, please update the component name
section of the description or use the component bot command.
TL;DR the following might be a quick fix:
diff --git a/lib/ansible/plugins/strategy/__init__.py b/lib/ansible/plugins/strategy/__init__.py
index efd69efe9b4..7665c8f6ff2 100644
--- a/lib/ansible/plugins/strategy/__init__.py
+++ b/lib/ansible/plugins/strategy/__init__.py
@@ -600,7 +600,7 @@ class StrategyBase:
# save the current state before failing it for later inspection
state_when_failed = iterator.get_state_for_host(original_host.name)
display.debug("marking %s as failed" % original_host.name)
- if original_task.run_once:
+ if original_task.run_once and not original_task.any_errors_fatal:
# if we're using run_once, we have to fail every host here
for h in self._inventory.get_hosts(iterator._play.hosts):
if h.name not in self._tqm._unreachable_hosts:
The underlying issue however I believe is that both run_once
and any_errors_fatal
are similar features. In the linear strategy run_once
implies any_errors_fatal
on the run_once
task. In https://github.com/ansible/ansible/pull/78680 we simplified the implementation of the any_errors_fatal
feature but it resulted in scenarios, like this issue describes, where these two features conflict with each other and hosts are failed twice.
I believe that a part of the problem is that run_once
and any_errors_fatal
are implemented in different places, in the general results processing in StrategyBase
and after the results are process in the linear
strategy, respectively. Since host_pinned
/free
do not support neither any_errors_fatal
or run_once
it might make sense to move both to the linear strategy although the compatibility for 3rd party strategies would have to be taken into account. Completion of https://github.com/ansible/ansible/issues/73483 would be beneficial to moving this forward too - it seems that the number of issues/PRs linked to that issue are slowly increasing.
FWIW I see the same behavior (RC=0 on 2.16 and RC=2 on 2.17) without setting any_errors_fatal: true
.
FWIW I see the same behavior (RC=0 on 2.16 and RC=2 on 2.17) without setting
any_errors_fatal: true
.
Yes, as I said:
In the linear strategy run_once implies any_errors_fatal on the run_once task.
so removing any_errors_fatal
from the play (block, task) in such a case does not effectively change anything internally.
Summary
When using block/rescue functionality in combination with
run_once
the ansible-playbook command returns code 2 when only some hosts are failing+rescued. When running the same playbook with --limit to only include a failing+rescued host it returns code 0. When running with --limit to only include a succeeding host it also returns code 0. Suspecting changes from #78680 to be causing this.Issue Type
Bug Report
Component Name
ansible
Ansible Version
Configuration
OS / Environment
Ubuntu 22.04.4 LTS
Steps to Reproduce
Using a similar playbook as the integration test added in #78680
Expected Results
Expecting return code 0.
Example from running with ansible-core version 2.16.7
The last 0 is the return code.
Actual Results
Getting return code 2.
Example from running with ansible-core version 2.17.0
Code of Conduct