From 052f3c2ece45fe4ab10509f3040c71324c1d4fbe Mon Sep 17 00:00:00 2001 From: James Cammarata Date: Thu, 16 Jul 2015 11:39:40 -0400 Subject: [PATCH] Fixing allow_duplicate and variable resolution bugs Fixes #11205 --- lib/ansible/playbook/block.py | 2 +- lib/ansible/playbook/role/__init__.py | 14 ++++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/ansible/playbook/block.py b/lib/ansible/playbook/block.py index 57a22c8cc1d..c20286c8d9f 100644 --- a/lib/ansible/playbook/block.py +++ b/lib/ansible/playbook/block.py @@ -56,7 +56,7 @@ class Block(Base, Become, Conditional, Taggable): all_vars = dict() if self._role: - all_vars.update(self._role.get_vars()) + all_vars.update(self._role.get_vars(self._dep_chain)) if self._parent_block: all_vars.update(self._parent_block.get_vars()) if self._task_include: diff --git a/lib/ansible/playbook/role/__init__.py b/lib/ansible/playbook/role/__init__.py index 71dd0038116..d2f03e32b58 100644 --- a/lib/ansible/playbook/role/__init__.py +++ b/lib/ansible/playbook/role/__init__.py @@ -160,6 +160,8 @@ class Role(Base, Become, Conditional, Taggable): if metadata: self._metadata = RoleMetadata.load(metadata, owner=self, loader=self._loader) self._dependencies = self._load_dependencies() + else: + self._metadata = RoleMetadata() task_data = self._load_role_yaml('tasks') if task_data: @@ -242,16 +244,16 @@ class Role(Base, Become, Conditional, Taggable): default_vars = combine_vars(default_vars, self._default_vars) return default_vars - def get_inherited_vars(self): + def get_inherited_vars(self, dep_chain=[]): inherited_vars = dict() - for parent in self._parents: - inherited_vars = combine_vars(inherited_vars, parent.get_inherited_vars()) + + for parent in dep_chain: inherited_vars = combine_vars(inherited_vars, parent._role_vars) inherited_vars = combine_vars(inherited_vars, parent._role_params) return inherited_vars - def get_vars(self): - all_vars = self.get_inherited_vars() + def get_vars(self, dep_chain=[]): + all_vars = self.get_inherited_vars(dep_chain) for dep in self.get_all_dependencies(): all_vars = combine_vars(all_vars, dep.get_vars()) @@ -296,7 +298,7 @@ class Role(Base, Become, Conditional, Taggable): at least one task was run ''' - return self._had_task_run and self._completed + return self._had_task_run and self._completed and not self._metadata.allow_duplicates def compile(self, play, dep_chain=[]): '''