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

Fixes #71306

(cherry picked from commit 9792d631b1)
This commit is contained in:
Martin Krizek 2020-08-27 19:22:45 +02:00 committed by GitHub
parent 3be597419d
commit 724b3648ea
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:
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):
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:
return False
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

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