From d55ddec9234755cb5fc026364b9e8d2b55130ce8 Mon Sep 17 00:00:00 2001 From: Jordan Borean Date: Tue, 26 Feb 2019 16:22:32 +1000 Subject: [PATCH] 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 f135960fc2e7572ce4e241b71cde64701a2d768c. * Add tests for failed scenario * Set failed task with EXPECTED FAILURE --- ...fix-handlers-on-failed-hosts-with-always-section.yaml | 2 -- lib/ansible/executor/play_iterator.py | 2 +- test/integration/targets/blocks/block_fail.yml | 5 +++++ test/integration/targets/blocks/block_fail_tasks.yml | 9 +++++++++ test/integration/targets/blocks/runme.sh | 8 ++++++++ 5 files changed, 23 insertions(+), 3 deletions(-) delete mode 100644 changelogs/fragments/52561-fix-handlers-on-failed-hosts-with-always-section.yaml create mode 100644 test/integration/targets/blocks/block_fail.yml create mode 100644 test/integration/targets/blocks/block_fail_tasks.yml diff --git a/changelogs/fragments/52561-fix-handlers-on-failed-hosts-with-always-section.yaml b/changelogs/fragments/52561-fix-handlers-on-failed-hosts-with-always-section.yaml deleted file mode 100644 index 36e7cd4a6b3..00000000000 --- a/changelogs/fragments/52561-fix-handlers-on-failed-hosts-with-always-section.yaml +++ /dev/null @@ -1,2 +0,0 @@ -bugfixes: - - Fix handlers on failed hosts with always section (https://github.com/ansible/ansible/issues/52561) diff --git a/lib/ansible/executor/play_iterator.py b/lib/ansible/executor/play_iterator.py index 63e4811789f..ab40ce6723e 100644 --- a/lib/ansible/executor/play_iterator.py +++ b/lib/ansible/executor/play_iterator.py @@ -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 diff --git a/test/integration/targets/blocks/block_fail.yml b/test/integration/targets/blocks/block_fail.yml new file mode 100644 index 00000000000..6b84d056254 --- /dev/null +++ b/test/integration/targets/blocks/block_fail.yml @@ -0,0 +1,5 @@ +--- +- name: Include tasks that have a failure in a block + hosts: localhost + tasks: + - include_tasks: block_fail_tasks.yml diff --git a/test/integration/targets/blocks/block_fail_tasks.yml b/test/integration/targets/blocks/block_fail_tasks.yml new file mode 100644 index 00000000000..6e70dc23739 --- /dev/null +++ b/test/integration/targets/blocks/block_fail_tasks.yml @@ -0,0 +1,9 @@ +- block: + - name: EXPECTED FAILURE + fail: + msg: failure + + always: + - name: run always task + debug: + msg: TEST COMPLETE diff --git a/test/integration/targets/blocks/runme.sh b/test/integration/targets/blocks/runme.sh index 20c89394240..ebce8581f41 100755 --- a/test/integration/targets/blocks/runme.sh +++ b/test/integration/targets/blocks/runme.sh @@ -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_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_wo_colors.out +[ "$(grep -c 'TEST COMPLETE' block_test.out)" = "$(egrep '^[0-9]+ plays in' block_test_wo_colors.out | cut -f1 -d' ')" ]