From e0df5b58889d0d8551b556630d97b8a3debcc8f1 Mon Sep 17 00:00:00 2001 From: James Cammarata Date: Sun, 1 Sep 2013 00:37:12 -0500 Subject: [PATCH] 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 } --- lib/ansible/playbook/play.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/ansible/playbook/play.py b/lib/ansible/playbook/play.py index a7ca1236cf..8a83d17308 100644 --- a/lib/ansible/playbook/play.py +++ b/lib/ansible/playbook/play.py @@ -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)