Fix include param precedence in variable manager

This commit is contained in:
James Cammarata 2015-11-19 09:01:51 -05:00
parent 78e4f176e6
commit 91500f8f5f
3 changed files with 15 additions and 0 deletions

View file

@ -272,6 +272,14 @@ class Task(Base, Conditional, Taggable, Become):
return all_vars
def get_include_params(self):
all_vars = dict()
if self._task_include:
all_vars.update(self._task_include.get_include_params())
if self.action == 'include':
all_vars.update(self.vars)
return all_vars
def copy(self, exclude_block=False):
new_me = super(Task, self).copy()

View file

@ -319,6 +319,12 @@ class VariableManager:
all_vars = combine_vars(all_vars, self._vars_cache.get(host.get_name(), dict()))
all_vars = combine_vars(all_vars, self._nonpersistent_fact_cache.get(host.name, dict()))
# special case for include tasks, where the include params
# may be specified in the vars field for the task, which should
# have higher precedence than the vars/np facts above
if task:
all_vars = combine_vars(all_vars, task.get_include_params())
all_vars = combine_vars(all_vars, self._extra_vars)
all_vars = combine_vars(all_vars, magic_variables)

View file

@ -173,6 +173,7 @@ class TestVariableManager(unittest.TestCase):
mock_task._role = None
mock_task.loop = None
mock_task.get_vars.return_value = dict(foo="bar")
mock_task.get_include_params.return_value = dict()
v = VariableManager()
self.assertEqual(v.get_vars(loader=fake_loader, task=mock_task, use_cache=False).get("foo"), "bar")