1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Fix parent attribute lookup to be default

Fixes #12526
This commit is contained in:
James Cammarata 2015-09-26 11:11:55 -04:00
parent a1c38a3fda
commit 6dd38c2a10
3 changed files with 64 additions and 50 deletions

View file

@ -105,7 +105,10 @@ class Base:
if hasattr(self, method): if hasattr(self, method):
return getattr(self, method)() return getattr(self, method)()
return self._attributes[prop_name] value = self._attributes[prop_name]
if value is None and hasattr(self, '_get_parent_attribute'):
value = self._get_parent_attribute(prop_name)
return value
@staticmethod @staticmethod
def _generic_s(prop_name, self, value): def _generic_s(prop_name, self, value):

View file

@ -271,45 +271,50 @@ class Block(Base, Become, Conditional, Taggable):
Generic logic to get the attribute or parent attribute for a block value. Generic logic to get the attribute or parent attribute for a block value.
''' '''
value = self._attributes[attr] value = None
if self._parent_block and (value is None or extend): try:
parent_value = getattr(self._parent_block, attr) value = self._attributes[attr]
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)
if extend:
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 extend:
value = self._extend_value(value, parent_value)
else:
value = parent_value
if len(self._dep_chain) and (not value or extend): if self._parent_block and (value is None or extend):
reverse_dep_chain = self._dep_chain[:] parent_value = getattr(self._parent_block, attr)
reverse_dep_chain.reverse() if extend:
for dep in reverse_dep_chain: value = self._extend_value(value, parent_value)
dep_value = getattr(dep, attr) else:
if extend: value = parent_value
value = self._extend_value(value, dep_value) if self._task_include and (value is None or extend):
else: parent_value = getattr(self._task_include, attr)
value = dep_value if extend:
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 extend:
value = self._extend_value(value, parent_value)
else:
value = parent_value
if value is not None and not extend: if len(self._dep_chain) and (not value or extend):
break reverse_dep_chain = self._dep_chain[:]
reverse_dep_chain.reverse()
for dep in reverse_dep_chain:
dep_value = getattr(dep, attr)
if extend:
value = self._extend_value(value, dep_value)
else:
value = dep_value
if self._play and (value is None or extend): if value is not None and not extend:
parent_value = getattr(self._play, attr) break
if extend:
value = self._extend_value(value, parent_value) if self._play and (value is None or extend):
else: parent_value = getattr(self._play, attr)
value = parent_value if extend:
value = self._extend_value(value, parent_value)
else:
value = parent_value
except KeyError:
pass
return value return value

View file

@ -363,19 +363,25 @@ class Task(Base, Conditional, Taggable, Become):
''' '''
Generic logic to get the attribute or parent attribute for a task value. Generic logic to get the attribute or parent attribute for a task value.
''' '''
value = self._attributes[attr] value = None
if self._block and (value is None or extend): try:
parent_value = getattr(self._block, attr) value = self._attributes[attr]
if extend:
value = self._extend_value(value, parent_value) if self._block and (value is None or extend):
else: parent_value = getattr(self._block, attr)
value = parent_value if extend:
if self._task_include and (value is None or extend): value = self._extend_value(value, parent_value)
parent_value = getattr(self._task_include, attr) else:
if extend: value = parent_value
value = self._extend_value(value, parent_value) if self._task_include and (value is None or extend):
else: parent_value = getattr(self._task_include, attr)
value = parent_value if extend:
value = self._extend_value(value, parent_value)
else:
value = parent_value
except KeyError:
pass
return value return value
def _get_attr_environment(self): def _get_attr_environment(self):