1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

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 }
This commit is contained in:
James Cammarata 2013-09-01 00:37:12 -05:00
parent 6f76ccf10e
commit e0df5b5888

View file

@ -169,6 +169,12 @@ class Play(object):
vars_data = utils.parse_yaml_from_file(vars) vars_data = utils.parse_yaml_from_file(vars)
if vars_data: if vars_data:
role_vars = utils.combine_vars(vars_data, role_vars) 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 # the meta directory contains the yaml that should
# hold the list of dependencies (if any) # hold the list of dependencies (if any)
meta = self._resolve_main(utils.path_dwim(self.basedir, os.path.join(role_path, 'meta'))) 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: if meta_data:
allow_dupes = utils.boolean(meta_data.get('allow_duplicates','')) allow_dupes = utils.boolean(meta_data.get('allow_duplicates',''))
if not allow_dupes: if not allow_dupes:
if dep.get('role') in self.included_roles: if dep in self.included_roles:
continue continue
else: 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(passed_vars, dep_vars)
dep_vars = utils.combine_vars(role_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'))) 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) vars_data = utils.parse_yaml_from_file(vars)
if vars_data: if vars_data:
dep_vars = utils.combine_vars(vars_data, dep_vars) 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: if 'role' in dep_vars:
del dep_vars['role'] del dep_vars['role']
self._build_role_dependencies([dep], dep_stack, passed_vars=dep_vars, level=level+1) self._build_role_dependencies([dep], dep_stack, passed_vars=dep_vars, level=level+1)