Skip to content

Commit

Permalink
Fix issue with vars precedence from roles
Browse files Browse the repository at this point in the history
  • Loading branch information
jimi-c committed Sep 30, 2014
1 parent c6bfd05 commit 313f26f
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/ansible/playbook/play.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ def _load_roles(self, roles, ds):
# flush handlers after pre_tasks
new_tasks.append(dict(meta='flush_handlers'))

roles = self._build_role_dependencies(roles, [], self.vars)
roles = self._build_role_dependencies(roles, [], {})

# give each role an uuid and
# make role_path available as variable to the task
Expand Down
12 changes: 10 additions & 2 deletions lib/ansible/runner/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,14 @@ def get_inject_vars(self, host):
module_vars_inject = utils.combine_vars(self.module_vars, module_vars_inject)
module_vars = template.template(self.basedir, self.module_vars, module_vars_inject)

# remove bad variables from the module vars, which may be in there due
# the way role declarations are specified in playbooks
if 'tags' in module_vars:
del module_vars['tags']
if 'when' in module_vars:
del module_vars['when']

# start building the dictionary of injected variables
inject = {}

# default vars are the lowest priority
Expand All @@ -608,10 +616,10 @@ def get_inject_vars(self, host):
inject = utils.combine_vars(inject, host_variables)
# then the setup_cache which contains facts gathered
inject = utils.combine_vars(inject, self.setup_cache.get(host, {}))
# then come the module variables
inject = utils.combine_vars(inject, module_vars)
# followed by vars (vars, vars_files, vars/main.yml)
inject = utils.combine_vars(inject, self.vars_cache.get(host, {}))
# then come the module variables
inject = utils.combine_vars(inject, module_vars)
# and finally -e vars are the highest priority
inject = utils.combine_vars(inject, self.extra_vars)
# and then special vars
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
- 'param_var == "param_var_role1"'
- 'vars_var == "vars_var"'
- 'vars_files_var == "vars_files_var"'
- 'vars_files_var_role == "vars_files_var_role3"'
- 'vars_files_var_role == "vars_files_var_role1"'
- 'defaults_file_var_role1 == "defaults_file_var_role1"'
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
- 'param_var == "param_var_role2"'
- 'vars_var == "vars_var"'
- 'vars_files_var == "vars_files_var"'
- 'vars_files_var_role == "vars_files_var_role3"'
- 'vars_files_var_role == "vars_files_var_role2"'
- 'defaults_file_var_role2 == "overridden by role vars"'

0 comments on commit 313f26f

Please sign in to comment.