From 54e70fc783199370c8f27b053c2d5ae3ea9ac7ee Mon Sep 17 00:00:00 2001 From: Phil Nelson Date: Tue, 20 Mar 2018 12:01:48 -0600 Subject: [PATCH] Fix name parameter templating in include_role module (#36372) An IncludedFile() object built using the original_task will have its _task bound to the original_task. The iterative reassignment of original_task._role_name during with_item loops leaves all returned included_files with the same ._task._role_name (the final name from the with_items list). This commit builds IncludedFile() objects from an original_task.copy() to avoid the problematic binding. --- lib/ansible/playbook/included_file.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/ansible/playbook/included_file.py b/lib/ansible/playbook/included_file.py index 7d9bd4e611..9945244105 100644 --- a/lib/ansible/playbook/included_file.py +++ b/lib/ansible/playbook/included_file.py @@ -146,13 +146,14 @@ class IncludedFile: if role_name is not None: role_name = templar.template(role_name) - original_task._role_name = role_name - for from_arg in original_task.FROM_ARGS: + new_task = original_task.copy() + new_task._role_name = role_name + for from_arg in new_task.FROM_ARGS: if from_arg in include_variables: from_key = from_arg.replace('_from', '') - original_task._from_files[from_key] = templar.template(include_variables[from_arg]) + new_task._from_files[from_key] = templar.template(include_variables[from_arg]) - inc_file = IncludedFile("role", include_variables, original_task, is_role=True) + inc_file = IncludedFile("role", include_variables, new_task, is_role=True) try: pos = included_files.index(inc_file)