summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Cammarata <jimi@sngx.net>2016-06-24 13:52:24 -0500
committerJames Cammarata <jimi@sngx.net>2016-06-24 13:52:24 -0500
commita2d998266841f1be5815fc4e8636a26ca682796f (patch)
treeca6bd30fa736fe0d624f133cfe9b8c4ef68e79a4
parent9330edd6b977c61e3e8dc9ef72fca84f70411808 (diff)
downloadansible-fixing_getattr_stuff.tar.gz
Fixing issues with getattr caused by 5a3493bfixing_getattr_stuff
-rw-r--r--lib/ansible/playbook/base.py36
-rw-r--r--lib/ansible/playbook/block.py4
-rw-r--r--lib/ansible/playbook/task.py6
3 files changed, 16 insertions, 30 deletions
diff --git a/lib/ansible/playbook/base.py b/lib/ansible/playbook/base.py
index 20fe442a5a..e3ae6374ae 100644
--- a/lib/ansible/playbook/base.py
+++ b/lib/ansible/playbook/base.py
@@ -110,32 +110,16 @@ class Base:
def _generic_g(prop_name, self):
method = "_get_attr_%s" % prop_name
if hasattr(self, method):
- return getattr(self, method)()
-
- # value_found is here because we think that value needs to be changed
- # in the future. self._attributes[prop_name] will return None
- # sometimes, apparently if it's not explicitly set in the playbook.
- # This would seem to make None a sentinel value. However, the user
- # could set the attribute to None explicitly (via !!nil) which will
- # not be recognized because it's being used as a sentinel. And
- # sometimes _attributes[prop_name] throws a KeyError so None doesn't
- # always mean that prop_name was not set. To work around these
- # issues, value_found is here so that if value's behaviour is changed
- # in the future, things can still be made to work.
- try:
- value = self._attributes[prop_name]
- value_found = True
- except KeyError:
- value = None
- value_found = False
-
- if not value_found and hasattr(self, '_get_parent_attribute'):
- value = self._get_parent_attribute(prop_name)
- value_found = True
-
- if value_found:
- return value
- raise AttributeError("'%s' object has no attribute '%s'" % (self.__class__.__name__, prop_name))
+ value = getattr(self, method)()
+ else:
+ try:
+ value = self._attributes[prop_name]
+ if value is None and hasattr(self, '_get_parent_attribute'):
+ value = self._get_parent_attribute(prop_name)
+ except KeyError:
+ raise AttributeError("'%s' object has no attribute '%s'" % (self.__class__.__name__, prop_name))
+
+ return value
@staticmethod
def _generic_s(prop_name, self, value):
diff --git a/lib/ansible/playbook/block.py b/lib/ansible/playbook/block.py
index 392b00b294..2994eadf56 100644
--- a/lib/ansible/playbook/block.py
+++ b/lib/ansible/playbook/block.py
@@ -296,13 +296,13 @@ class Block(Base, Become, Conditional, Taggable):
value = self._attributes[attr]
if self._parent_block and (value is None or extend):
- parent_value = getattr(self._parent_block, attr)
+ parent_value = getattr(self._parent_block, attr, None)
if extend:
value = self._extend_value(value, parent_value)
else:
value = parent_value
if self._task_include and (value is None or extend):
- parent_value = getattr(self._task_include, attr)
+ parent_value = getattr(self._task_include, attr, None)
if extend:
value = self._extend_value(value, parent_value)
else:
diff --git a/lib/ansible/playbook/task.py b/lib/ansible/playbook/task.py
index 309579c85a..c55f32b2c4 100644
--- a/lib/ansible/playbook/task.py
+++ b/lib/ansible/playbook/task.py
@@ -415,13 +415,13 @@ class Task(Base, Conditional, Taggable, Become):
value = self._attributes[attr]
if self._block and (value is None or extend):
- parent_value = getattr(self._block, attr)
+ parent_value = getattr(self._block, attr, None)
if extend:
value = self._extend_value(value, parent_value)
else:
value = parent_value
if self._task_include and (value is None or extend):
- parent_value = getattr(self._task_include, attr)
+ parent_value = getattr(self._task_include, attr, None)
if extend:
value = self._extend_value(value, parent_value)
else:
@@ -447,3 +447,5 @@ class Task(Base, Conditional, Taggable, Become):
'''
return self._get_parent_attribute('any_errors_fatal')
+ def _get_attr_loop(self):
+ return self._attributes['loop']