1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Revert Clear failed state in always only if we did rescue (#52968)

* Revert "Clear failed state in always only if we did rescue (#52829)"

This reverts commit f135960fc2.

* Add tests for failed scenario

* Set failed task with EXPECTED FAILURE
This commit is contained in:
Jordan Borean 2019-02-26 16:22:32 +10:00 committed by GitHub
parent 344a81daec
commit d55ddec923
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 23 additions and 3 deletions

View file

@ -1,2 +0,0 @@
bugfixes:
- Fix handlers on failed hosts with always section (https://github.com/ansible/ansible/issues/52561)

View file

@ -484,7 +484,7 @@ class PlayIterator:
elif state.fail_state != self.FAILED_NONE:
if state.run_state == self.ITERATING_RESCUE and state.fail_state & self.FAILED_RESCUE == 0:
return False
elif state.run_state == self.ITERATING_ALWAYS and state.fail_state & self.FAILED_ALWAYS == 0 and state.did_rescue:
elif state.run_state == self.ITERATING_ALWAYS and state.fail_state & self.FAILED_ALWAYS == 0:
return False
else:
return not state.did_rescue

View file

@ -0,0 +1,5 @@
---
- name: Include tasks that have a failure in a block
hosts: localhost
tasks:
- include_tasks: block_fail_tasks.yml

View file

@ -0,0 +1,9 @@
- block:
- name: EXPECTED FAILURE
fail:
msg: failure
always:
- name: run always task
debug:
msg: TEST COMPLETE

View file

@ -26,3 +26,11 @@ env python -c \
'import sys, re; sys.stdout.write(re.sub("\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]", "", sys.stdin.read()))' \
<block_test.out >block_test_wo_colors.out
[ "$(grep -c 'TEST COMPLETE' block_test.out)" = "$(egrep '^[0-9]+ plays in' block_test_wo_colors.out | cut -f1 -d' ')" ]
# run test that includes tasks that fail inside a block with always
rm -f block_test.out block_test_wo_colors.out
ansible-playbook -vv block_fail.yml -i ../../inventory "$@" | tee block_test.out
env python -c \
'import sys, re; sys.stdout.write(re.sub("\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]", "", sys.stdin.read()))' \
<block_test.out >block_test_wo_colors.out
[ "$(grep -c 'TEST COMPLETE' block_test.out)" = "$(egrep '^[0-9]+ plays in' block_test_wo_colors.out | cut -f1 -d' ')" ]