A couple more tweaks to role default variables/dependencies

* Default variables are now fed directly into roles, just like the
  other variables, so that roles see their unique values rather
  than those set at the global level.

* Role dependency duplicates are now determined by checking the params used
  when specifying them as dependencies rather than just on the name of the
  role. For example, the following would be included twice without having
  to specify "allow_duplicates: true":

  dependencies:
  - { role: foo, x: 1 }
  - { role: foo, x: 2 }
pull/3983/merge
James Cammarata 11 years ago
parent 6f76ccf10e
commit e0df5b5888

@ -169,6 +169,12 @@ class Play(object):
vars_data = utils.parse_yaml_from_file(vars)
if vars_data:
role_vars = utils.combine_vars(vars_data, role_vars)
defaults = self._resolve_main(utils.path_dwim(self.basedir, os.path.join(role_path, 'defaults')))
defs_data = {}
if os.path.isfile(defaults):
defs_data = utils.parse_yaml_from_file(defaults)
if defs_data:
role_vars = utils.combine_vars(role_vars, defs_data)
# the meta directory contains the yaml that should
# hold the list of dependencies (if any)
meta = self._resolve_main(utils.path_dwim(self.basedir, os.path.join(role_path, 'meta')))
@ -184,10 +190,10 @@ class Play(object):
if meta_data:
allow_dupes = utils.boolean(meta_data.get('allow_duplicates',''))
if not allow_dupes:
if dep.get('role') in self.included_roles:
if dep in self.included_roles:
continue
else:
self.included_roles.append(dep.get('role'))
self.included_roles.append(dep)
dep_vars = utils.combine_vars(passed_vars, dep_vars)
dep_vars = utils.combine_vars(role_vars, dep_vars)
vars = self._resolve_main(utils.path_dwim(self.basedir, os.path.join(dep_path, 'vars')))
@ -196,6 +202,12 @@ class Play(object):
vars_data = utils.parse_yaml_from_file(vars)
if vars_data:
dep_vars = utils.combine_vars(vars_data, dep_vars)
defaults = self._resolve_main(utils.path_dwim(self.basedir, os.path.join(dep_path, 'defaults')))
defs_data = {}
if os.path.isfile(defaults):
defs_data = utils.parse_yaml_from_file(defaults)
if defs_data:
dep_vars = utils.combine_vars(dep_vars, defs_data)
if 'role' in dep_vars:
del dep_vars['role']
self._build_role_dependencies([dep], dep_stack, passed_vars=dep_vars, level=level+1)

Loading…
Cancel
Save