From f427955640dab75f8be4f97d3477e5303346c455 Mon Sep 17 00:00:00 2001 From: James Cammarata Date: Mon, 21 Mar 2016 01:38:48 -0400 Subject: [PATCH] Make default var lookup for tasks follow the dep chain Related to #14296 (@jjshoe's follow-up example on that issue) --- lib/ansible/playbook/role/__init__.py | 5 ++++- lib/ansible/vars/__init__.py | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/ansible/playbook/role/__init__.py b/lib/ansible/playbook/role/__init__.py index 133dd50acca..b86ad0fd024 100644 --- a/lib/ansible/playbook/role/__init__.py +++ b/lib/ansible/playbook/role/__init__.py @@ -252,10 +252,13 @@ class Role(Base, Become, Conditional, Taggable): def get_parents(self): return self._parents - def get_default_vars(self): + def get_default_vars(self, dep_chain=[]): default_vars = dict() for dep in self.get_all_dependencies(): default_vars = combine_vars(default_vars, dep.get_default_vars()) + if dep_chain: + for parent in dep_chain: + default_vars = combine_vars(default_vars, parent._default_vars) default_vars = combine_vars(default_vars, self._default_vars) return default_vars diff --git a/lib/ansible/vars/__init__.py b/lib/ansible/vars/__init__.py index 2d1a872f294..c95d25c5a32 100644 --- a/lib/ansible/vars/__init__.py +++ b/lib/ansible/vars/__init__.py @@ -220,7 +220,7 @@ class VariableManager: # sure it sees its defaults above any other roles, as we previously # (v1) made sure each task had a copy of its roles default vars if task and task._role is not None: - all_vars = combine_vars(all_vars, task._role.get_default_vars()) + all_vars = combine_vars(all_vars, task._role.get_default_vars(dep_chain=task._block._dep_chain)) if host: # next, if a host is specified, we load any vars from group_vars