From 50905b980d8b119d8a98e2b783c954e3c61d87be Mon Sep 17 00:00:00 2001 From: Matt Martz Date: Mon, 9 Jul 2018 10:27:00 -0500 Subject: [PATCH] Support item label in v2_playbook_on_include (#42478) * Support item label in v2_playbook_on_include. Fixes #42301 * test fixes --- lib/ansible/playbook/included_file.py | 4 ++++ lib/ansible/plugins/callback/default.py | 2 ++ test/integration/targets/include_import/runme.sh | 4 ++-- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/ansible/playbook/included_file.py b/lib/ansible/playbook/included_file.py index a6c9f76283..1a6a519fc7 100644 --- a/lib/ansible/playbook/included_file.py +++ b/lib/ansible/playbook/included_file.py @@ -93,6 +93,10 @@ class IncludedFile: task_vars[loop_var] = include_variables[loop_var] = include_result[loop_var] if index_var and index_var in include_result: task_vars[index_var] = include_variables[index_var] = include_result[index_var] + if '_ansible_item_label' in include_result: + task_vars['_ansible_item_label'] = include_variables['_ansible_item_label'] = include_result['_ansible_item_label'] + if original_task.no_log and '_ansible_no_log' not in include_variables: + task_vars['_ansible_no_log'] = include_variables['_ansible_no_log'] = original_task.no_log if original_task.action in ('include', 'include_tasks'): include_file = None diff --git a/lib/ansible/plugins/callback/default.py b/lib/ansible/plugins/callback/default.py index f58d566e10..bee9402d04 100644 --- a/lib/ansible/plugins/callback/default.py +++ b/lib/ansible/plugins/callback/default.py @@ -269,6 +269,8 @@ class CallbackModule(CallbackBase): def v2_playbook_on_include(self, included_file): msg = 'included: %s for %s' % (included_file._filename, ", ".join([h.name for h in included_file._hosts])) + if 'item' in included_file._args: + msg += " => (item=%s)" % (self._get_item_label(included_file._args),) self._display.display(msg, color=C.COLOR_SKIP) def v2_playbook_on_stats(self, stats): diff --git a/test/integration/targets/include_import/runme.sh b/test/integration/targets/include_import/runme.sh index 8f0550e2b3..c2b4abf4a7 100755 --- a/test/integration/targets/include_import/runme.sh +++ b/test/integration/targets/include_import/runme.sh @@ -76,6 +76,6 @@ fi # Test that duplicate items in loop are not deduped ANSIBLE_STRATEGY='linear' ansible-playbook tasks/test_include_dupe_loop.yml -i ../../inventory "$@" | tee test_include_dupe_loop.out -test "$(grep -c 'item=foo' test_include_dupe_loop.out)" = 3 +test "$(grep -c '"item=foo"' test_include_dupe_loop.out)" = 3 ANSIBLE_STRATEGY='free' ansible-playbook tasks/test_include_dupe_loop.yml -i ../../inventory "$@" | tee test_include_dupe_loop.out -test "$(grep -c 'item=foo' test_include_dupe_loop.out)" = 3 \ No newline at end of file +test "$(grep -c '"item=foo"' test_include_dupe_loop.out)" = 3 \ No newline at end of file