mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-23 05:10:22 -07:00
Make sure include_role inherit variables from parent role (#18627)
* Make sure include_role inherit variables from parent role Setting the parent of task blocks generated by include_role after they have been produced is not sufficient - it means the tasks don't have the correct dependency chain set afterwards, and therefore, don't properly inherit variables from outer roles. In addition to manually setting the parents, pass the dep_chain when compiling the role, such that variables are correctly imported. Fixes #18540. * Add tests for include_role * Fix include_role variable inheritance for multiple parent levels
This commit is contained in:
parent
00f8945159
commit
57f4a9885e
2 changed files with 238 additions and 3 deletions
|
@ -76,10 +76,16 @@ class IncludeRole(Task):
|
|||
actual_role = Role.load(ri, myplay, parent_role=self._parent_role, from_files=self._from_files)
|
||||
actual_role._metadata.allow_duplicates = self.allow_duplicates
|
||||
|
||||
# compile role
|
||||
blocks = actual_role.compile(play=myplay)
|
||||
# compile role with parent roles as dependencies to ensure they inherit
|
||||
# variables
|
||||
if not self._parent_role:
|
||||
dep_chain = []
|
||||
else:
|
||||
dep_chain = list(self._parent_role._parents)
|
||||
dep_chain.extend(self._parent_role.get_all_dependencies())
|
||||
dep_chain.append(self._parent_role)
|
||||
|
||||
# set parent to ensure proper inheritance
|
||||
blocks = actual_role.compile(play=myplay, dep_chain=dep_chain)
|
||||
for b in blocks:
|
||||
b._parent = self
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue