Sloane Hertel 3 days ago committed by GitHub
commit efa25e93d3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,3 @@
---
bugfixes:
- Fix the issue of playbook with any_errors_fatal as true, the rescue section only executes on the host where a fail task with run_once as true is triggered, not affecting other hosts as expected.(https://github.com/ansible/ansible/issues/83292)

@ -562,7 +562,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:

@ -166,7 +166,7 @@ class StrategyModule(StrategyBase):
results.extend(self._execute_meta(task, play_context, iterator, host))
if task._get_meta() not in ('noop', 'reset_connection', 'end_host', 'role_complete', 'flush_handlers', 'end_role'):
run_once = True
if (task.any_errors_fatal or run_once) and not task.ignore_errors:
if task.any_errors_fatal and not task.ignore_errors:
any_errors_fatal = True
else:
# handle step if needed, skip meta actions as they are used internally
@ -179,7 +179,7 @@ class StrategyModule(StrategyBase):
run_once = action and getattr(action, 'BYPASS_HOST_LOOP', False) or templar.template(task.run_once)
if (task.any_errors_fatal or run_once) and not task.ignore_errors:
if task.any_errors_fatal and not task.ignore_errors:
any_errors_fatal = True
if not callback_sent:

@ -0,0 +1,19 @@
- hosts: testhost,testhost2
gather_facts: false
any_errors_fatal: "{{ any_errors_fatal | default(omit) }}"
tasks:
- block:
- debug:
msg: Some task running for all hosts
- fail:
run_once: "{{ run_once | default(omit) }}"
- name: any_errors_fatal fails all hosts when any of them fails
debug:
msg: SHOULD NOT HAPPEN
rescue:
- name: Rescues both hosts
debug:
msg: rescuedd
- name: You can recover from fatal errors by adding a rescue section to the block.
debug:
msg: recovered

@ -47,3 +47,21 @@ ansible-playbook -i inventory "$@" 80981.yml | tee out.txt
[ "$(grep -c 'SHOULD NOT HAPPEN' out.txt)" -eq 0 ]
[ "$(grep -c 'rescuedd' out.txt)" -eq 2 ]
[ "$(grep -c 'recovered' out.txt)" -eq 2 ]
args=(
"-e any_errors_fatal=true"
"-e run_once=true"
"-e any_errors_fatal=true run_once=true"
""
)
for arg in "${args[@]}"; do
if [ -z "$arg" ]; then
ansible-playbook -i inventory "$@" 83292.yml | tee out.txt
else
ansible-playbook -i inventory "$@" 83292.yml "$arg" | tee out.txt
fi
[ "$(grep -c 'SHOULD NOT HAPPEN' out.txt)" -eq 0 ]
[ "$(grep -c 'rescuedd' out.txt)" -eq 2 ]
[ "$(grep -c 'recovered' out.txt)" -eq 2 ]
done

Loading…
Cancel
Save