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.
This commit is contained in:
Phil Nelson 2018-03-20 12:01:48 -06:00 committed by ansibot
parent 6c3e565ba3
commit 54e70fc783

View file

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