-
Notifications
You must be signed in to change notification settings - Fork 23.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix name parameter templating in include_role module #36372
Fix name parameter templating in include_role module #36372
Conversation
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.
Thanks for logging this @fullyint , I'm hoping to use include_role: name: {{ loopedVar }} with with_items/with_dict but running into this exact problem (along with the other referenced issues). Hoping this can be merged! You tested against 2.6, hopefully we can see this in 2.5 as well! Only work around I can think of at the moment is to write out to a temporary playbook file and execute it.. seems messy. :( |
rebuild_merge |
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. (cherry picked from commit 54e70fc)
* Tests for ansible#36372 * Tests for ansible#36372 * Tests for ansible#36372 (cherry picked from commit 8c4f349)
* 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. (cherry picked from commit 54e70fc) * Test include role with items in name #36372 (#37001) * Tests for #36372 * Tests for #36372 * Tests for #36372 (cherry picked from commit 8c4f349) * Add changelog for #36372
SUMMARY
Followup to #33386 and #21285.
Fixes problem that
include_role
looping overwith_items
andname: "{{ item }}"
will use the samename
for all items in the loop.In the current code, an
IncludedFile()
object built using theoriginal_task
will have itsinc_file._task
bound to theoriginal_task
. The iterative reassignment oforiginal_task._role_name
duringwith_items
loops leaves all returnedincluded_files
with the sameinc_file._task._role_name
. All have the final name from thewith_items
list.This PR builds
IncludedFile()
objects from anoriginal_task.copy()
to avoid the problematic binding.ISSUE TYPE
COMPONENT NAME
include_role module
ANSIBLE VERSION
ADDITIONAL INFORMATION
To reproduce, create a test playbook with a looping
include_role
:Create
role1
androle2
:Output from current devel branch
The
include_role
task runsrole2
both times, despitewith_items: ['role1', 'role2']
.Output after applying this PR