_check_failed_state: always use the current/nested state (#71347) (#71456)

Fixes #71306

(cherry picked from commit 9792d631b1)
pull/71335/head
Martin Krizek 4 years ago committed by GitHub
parent 6b4977e3f4
commit 15f3426971
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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:

@ -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!"

@ -74,3 +74,12 @@ cat rc_test.out
[ "$(grep -c 'Failure in always' rc_test.out )" -eq 1 ] [ "$(grep -c 'Failure in always' rc_test.out )" -eq 1 ]
[ "$(grep -c 'DID NOT RUN' rc_test.out )" -eq 0 ] [ "$(grep -c 'DID NOT RUN' rc_test.out )" -eq 0 ]
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…
Cancel
Save