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

Support item label in v2_playbook_on_include (#42478)

* Support item label in v2_playbook_on_include. Fixes #42301

* test fixes
This commit is contained in:
Matt Martz 2018-07-09 10:27:00 -05:00 committed by Brian Coca
parent 9bd7bd5d46
commit 50905b980d
3 changed files with 8 additions and 2 deletions

View file

@ -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

View file

@ -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):

View file

@ -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
test "$(grep -c '"item=foo"' test_include_dupe_loop.out)" = 3