* 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 commit54e70fc783
) * Test include role with items in name #36372 (#37001) * Tests for #36372 * Tests for #36372 * Tests for #36372 (cherry picked from commit8c4f349743
) * Add changelog for #36372
This commit is contained in:
parent
687780323a
commit
0b0bb65198
5 changed files with 16 additions and 5 deletions
2
changelogs/fragments/include_role_templating.yaml
Normal file
2
changelogs/fragments/include_role_templating.yaml
Normal file
|
@ -0,0 +1,2 @@
|
|||
bugfixes:
|
||||
- include_role - Fix parameter templating (https://github.com/ansible/ansible/pull/36372)
|
|
@ -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)
|
||||
|
|
|
@ -47,12 +47,18 @@
|
|||
- name: Test role include with a loop
|
||||
include_role:
|
||||
name: "{{ item }}"
|
||||
register: loop_test
|
||||
with_items:
|
||||
- role1
|
||||
- role3
|
||||
- role2
|
||||
|
||||
- name: Assert that roles run with_items
|
||||
assert:
|
||||
that:
|
||||
- _role1_result.msg == 'In role1'
|
||||
- _role2_result.msg == 'In role2'
|
||||
- _role3_result.msg == 'In role3'
|
||||
|
||||
- name: Test including a task file from a role
|
||||
include_role:
|
||||
name: role1
|
||||
|
|
|
@ -1,2 +1,3 @@
|
|||
- debug:
|
||||
msg: In role2
|
||||
register: _role2_result
|
||||
|
|
|
@ -1,2 +1,3 @@
|
|||
- debug:
|
||||
msg: In role3
|
||||
register: _role3_result
|
||||
|
|
Loading…
Reference in a new issue