mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Adding evaluation of role vars as the dep tree is built
This allows variables to be inserted into the role scope specifically while also being inserted into the global scope.
This commit is contained in:
parent
e12b99dba6
commit
d8a7a2d1b2
1 changed files with 11 additions and 4 deletions
|
@ -147,7 +147,7 @@ class Play(object):
|
||||||
|
|
||||||
return (path, role_vars)
|
return (path, role_vars)
|
||||||
|
|
||||||
def _build_role_dependencies(self, roles, dep_stack, vars={}, level=0):
|
def _build_role_dependencies(self, roles, dep_stack, passed_vars={}, level=0):
|
||||||
# this number is arbitrary, but it seems sane
|
# this number is arbitrary, but it seems sane
|
||||||
if level > 20:
|
if level > 20:
|
||||||
raise errors.AnsibleError("too many levels of recursion while resolving role dependencies")
|
raise errors.AnsibleError("too many levels of recursion while resolving role dependencies")
|
||||||
|
@ -162,13 +162,20 @@ class Play(object):
|
||||||
dependencies = data.get('dependencies',[])
|
dependencies = data.get('dependencies',[])
|
||||||
for dep in dependencies:
|
for dep in dependencies:
|
||||||
(dep_path,dep_vars) = self._get_role_path(dep)
|
(dep_path,dep_vars) = self._get_role_path(dep)
|
||||||
|
vars = self._resolve_main(utils.path_dwim(self.basedir, os.path.join(dep_path, 'vars')))
|
||||||
|
vars_data = {}
|
||||||
|
if os.path.isfile(vars):
|
||||||
|
vars_data = utils.parse_yaml_from_file(vars)
|
||||||
dep_vars.update(role_vars)
|
dep_vars.update(role_vars)
|
||||||
for k in vars.keys():
|
for k in passed_vars.keys():
|
||||||
if not k in dep_vars:
|
if not k in dep_vars:
|
||||||
dep_vars[k] = vars[k]
|
dep_vars[k] = passed_vars[k]
|
||||||
|
for k in vars_data.keys():
|
||||||
|
if not k in dep_vars:
|
||||||
|
dep_vars[k] = vars_data[k]
|
||||||
if 'role' in dep_vars:
|
if 'role' in dep_vars:
|
||||||
del dep_vars['role']
|
del dep_vars['role']
|
||||||
self._build_role_dependencies([dep], dep_stack, vars=dep_vars, level=level+1)
|
self._build_role_dependencies([dep], dep_stack, passed_vars=dep_vars, level=level+1)
|
||||||
dep_stack.append([dep,dep_path,dep_vars])
|
dep_stack.append([dep,dep_path,dep_vars])
|
||||||
# only add the current role when we're at the top level,
|
# only add the current role when we're at the top level,
|
||||||
# otherwise we'll end up in a recursive loop
|
# otherwise we'll end up in a recursive loop
|
||||||
|
|
Loading…
Reference in a new issue