From 07a9a54b0efb8d15bb03fbb3bf6477318d53b8e6 Mon Sep 17 00:00:00 2001 From: James Cammarata Date: Tue, 26 Jan 2016 13:10:23 -0500 Subject: [PATCH] Fix lookup of parent attribute when parent doesn't have the attr Fixes #14100 --- lib/ansible/playbook/block.py | 21 ++++++++------------- lib/ansible/playbook/task.py | 6 +----- 2 files changed, 9 insertions(+), 18 deletions(-) diff --git a/lib/ansible/playbook/block.py b/lib/ansible/playbook/block.py index b31ffbcfe8..095e6b338d 100644 --- a/lib/ansible/playbook/block.py +++ b/lib/ansible/playbook/block.py @@ -298,18 +298,18 @@ class Block(Base, Become, Conditional, Taggable): value = self._extend_value(value, parent_value) else: value = parent_value - if self._role and (value is None or extend): - parent_value = getattr(self._role, attr) + if self._role and (value is None or extend) and hasattr(self._role, attr): + parent_value = getattr(self._role, attr, None) if extend: value = self._extend_value(value, parent_value) else: value = parent_value - if len(self._dep_chain) and (not value or extend): + if len(self._dep_chain) and (value is None or extend): reverse_dep_chain = self._dep_chain[:] reverse_dep_chain.reverse() for dep in reverse_dep_chain: - dep_value = getattr(dep, attr) + dep_value = getattr(dep, attr, None) if extend: value = self._extend_value(value, dep_value) else: @@ -317,14 +317,13 @@ class Block(Base, Become, Conditional, Taggable): if value is not None and not extend: break - - if self._play and (value is None or extend): - parent_value = getattr(self._play, attr) + if self._play and (value is None or extend) and hasattr(self._play, attr): + parent_value = getattr(self._play, attr, None) if extend: value = self._extend_value(value, parent_value) else: value = parent_value - except KeyError: + except KeyError as e: pass return value @@ -344,11 +343,7 @@ class Block(Base, Become, Conditional, Taggable): ''' Override for the 'tags' getattr fetcher, used from Base. ''' - any_errors_fatal = self._attributes['any_errors_fatal'] - if hasattr(self, '_get_parent_attribute'): - if self._get_parent_attribute('any_errors_fatal'): - any_errors_fatal = True - return any_errors_fatal + return self._get_parent_attribute('any_errors_fatal') def filter_tagged_tasks(self, play_context, all_vars): ''' diff --git a/lib/ansible/playbook/task.py b/lib/ansible/playbook/task.py index 154ff53d5e..6bd3caaca5 100644 --- a/lib/ansible/playbook/task.py +++ b/lib/ansible/playbook/task.py @@ -419,9 +419,5 @@ class Task(Base, Conditional, Taggable, Become): ''' Override for the 'tags' getattr fetcher, used from Base. ''' - any_errors_fatal = self._attributes['any_errors_fatal'] - if hasattr(self, '_get_parent_attribute'): - if self._get_parent_attribute('any_errors_fatal'): - any_errors_fatal = True - return any_errors_fatal + return self._get_parent_attribute('any_errors_fatal')