_check_failed_state: always use the current/nested state (#71347)
Fixes #71306
This commit is contained in:
parent
f5b6df14ab
commit
9792d631b1
4 changed files with 28 additions and 1 deletions
2
changelogs/fragments/71306-fix-exit-code-no-failure.yml
Normal file
2
changelogs/fragments/71306-fix-exit-code-no-failure.yml
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
bugfixes:
|
||||||
|
- Fix an exit code for a non-failing playbook (https://github.com/ansible/ansible/issues/71306)
|
|
@ -491,7 +491,7 @@ class PlayIterator:
|
||||||
else:
|
else:
|
||||||
return not (state.did_rescue and state.fail_state & self.FAILED_ALWAYS == 0)
|
return not (state.did_rescue and state.fail_state & self.FAILED_ALWAYS == 0)
|
||||||
elif state.run_state == self.ITERATING_TASKS and self._check_failed_state(state.tasks_child_state):
|
elif state.run_state == self.ITERATING_TASKS and self._check_failed_state(state.tasks_child_state):
|
||||||
cur_block = self._blocks[state.cur_block]
|
cur_block = state._blocks[state.cur_block]
|
||||||
if len(cur_block.rescue) > 0 and state.fail_state & self.FAILED_RESCUE == 0:
|
if len(cur_block.rescue) > 0 and state.fail_state & self.FAILED_RESCUE == 0:
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
|
|
16
test/integration/targets/blocks/issue71306.yml
Normal file
16
test/integration/targets/blocks/issue71306.yml
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
- hosts: all
|
||||||
|
gather_facts: no
|
||||||
|
tasks:
|
||||||
|
- block:
|
||||||
|
- block:
|
||||||
|
- block:
|
||||||
|
- name: EXPECTED FAILURE
|
||||||
|
fail:
|
||||||
|
when: ansible_host == "host1"
|
||||||
|
|
||||||
|
- debug:
|
||||||
|
msg: "I am successful!"
|
||||||
|
run_once: true
|
||||||
|
rescue:
|
||||||
|
- debug:
|
||||||
|
msg: "Attemp 1 failed!"
|
|
@ -84,3 +84,12 @@ cat rc_test.out
|
||||||
[ "$(grep -c 'rescued=3' rc_test.out)" -eq 1 ]
|
[ "$(grep -c 'rescued=3' rc_test.out)" -eq 1 ]
|
||||||
[ "$(grep -c 'failed=0' rc_test.out)" -eq 1 ]
|
[ "$(grep -c 'failed=0' rc_test.out)" -eq 1 ]
|
||||||
rm -f rc_test.out
|
rm -f rc_test.out
|
||||||
|
|
||||||
|
# https://github.com/ansible/ansible/issues/71306
|
||||||
|
set +e
|
||||||
|
exit_code=0
|
||||||
|
ansible-playbook -i host1,host2 -vv issue71306.yml > rc_test.out || exit_code=$?
|
||||||
|
set -e
|
||||||
|
cat rc_test.out
|
||||||
|
[ $exit_code -eq 0 ]
|
||||||
|
rm -f rc_test_out
|
||||||
|
|
Loading…
Reference in a new issue