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

Fixes #71306
This commit is contained in:
Martin Krizek 2020-08-26 07:07:34 +02:00 committed by GitHub
parent f5b6df14ab
commit 9792d631b1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 28 additions and 1 deletions

View file

@ -0,0 +1,2 @@
bugfixes:
- Fix an exit code for a non-failing playbook (https://github.com/ansible/ansible/issues/71306)

View file

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

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

View file

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