From a6d4c3ff7cf43c24be6622102cee834fc5096496 Mon Sep 17 00:00:00 2001 From: Martin Krizek Date: Tue, 13 Sep 2022 09:50:10 +0200 Subject: [PATCH] Print skip reason for skipped meta tasks instead of an empty msg in -vv (#78681) Fixes #77315 --- changelogs/fragments/77315-fix-meta-vv-header.yml | 2 ++ lib/ansible/plugins/strategy/__init__.py | 6 ++++-- test/integration/targets/meta_tasks/runme.sh | 4 ++-- 3 files changed, 8 insertions(+), 4 deletions(-) create mode 100644 changelogs/fragments/77315-fix-meta-vv-header.yml diff --git a/changelogs/fragments/77315-fix-meta-vv-header.yml b/changelogs/fragments/77315-fix-meta-vv-header.yml new file mode 100644 index 00000000000..cddc7441fe0 --- /dev/null +++ b/changelogs/fragments/77315-fix-meta-vv-header.yml @@ -0,0 +1,2 @@ +bugfixes: + - Fix ``-vv`` output for meta tasks to not have an empty message when skipped, print the skip reason instead. (https://github.com/ansible/ansible/issues/77315) diff --git a/lib/ansible/plugins/strategy/__init__.py b/lib/ansible/plugins/strategy/__init__.py index fd295055eff..2f04a3f73ff 100644 --- a/lib/ansible/plugins/strategy/__init__.py +++ b/lib/ansible/plugins/strategy/__init__.py @@ -912,7 +912,7 @@ class StrategyBase: return task.evaluate_conditional(templar, all_vars) skipped = False - msg = '' + msg = meta_action skip_reason = '%s conditional evaluated to False' % meta_action if isinstance(task, Handler): self._tqm.send_callback('v2_playbook_on_handler_task_start', task) @@ -1049,7 +1049,9 @@ class StrategyBase: else: result['changed'] = False - display.vv("META: %s" % msg) + if not task.implicit: + header = skip_reason if skipped else msg + display.vv(f"META: {header}") if isinstance(task, Handler): task.remove_host(target_host) diff --git a/test/integration/targets/meta_tasks/runme.sh b/test/integration/targets/meta_tasks/runme.sh index bee6636314c..f7d8d8973f4 100755 --- a/test/integration/targets/meta_tasks/runme.sh +++ b/test/integration/targets/meta_tasks/runme.sh @@ -6,7 +6,7 @@ set -eux for test_strategy in linear free; do out="$(ansible-playbook test_end_host.yml -i inventory.yml -e test_strategy=$test_strategy -vv "$@")" - grep -q "META: end_host conditional evaluated to false, continuing execution for testhost" <<< "$out" + grep -q "META: end_host conditional evaluated to False, continuing execution for testhost" <<< "$out" grep -q "META: ending play for testhost2" <<< "$out" grep -q '"skip_reason": "end_host conditional evaluated to False, continuing execution for testhost"' <<< "$out" grep -q "play not ended for testhost" <<< "$out" @@ -14,7 +14,7 @@ for test_strategy in linear free; do out="$(ansible-playbook test_end_host_fqcn.yml -i inventory.yml -e test_strategy=$test_strategy -vv "$@")" - grep -q "META: end_host conditional evaluated to false, continuing execution for testhost" <<< "$out" + grep -q "META: end_host conditional evaluated to False, continuing execution for testhost" <<< "$out" grep -q "META: ending play for testhost2" <<< "$out" grep -q '"skip_reason": "end_host conditional evaluated to False, continuing execution for testhost"' <<< "$out" grep -q "play not ended for testhost" <<< "$out"