mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-06 13:22:48 +00:00
Skip self._parent on dynamic, defer to grandparent for attr lookup (#38827)
* Skip self._parent on dynamic, defer to grandparent for attr lookup * Revert _inheritable * Add tests for include inheritance from static blocks Fixes #38037 #36194
This commit is contained in:
@@ -174,8 +174,6 @@ class Base(with_metaclass(BaseMeta, object)):
|
||||
'su', 'su_user', 'su_pass', 'su_exe', 'su_flags',
|
||||
]
|
||||
|
||||
_inheritable = True
|
||||
|
||||
def __init__(self):
|
||||
|
||||
# initialize the data loader and variable manager, which will be provided
|
||||
|
||||
@@ -298,13 +298,20 @@ class Block(Base, Become, Conditional, Taggable):
|
||||
prepend = self._valid_attrs[attr].prepend
|
||||
try:
|
||||
value = self._attributes[attr]
|
||||
if self._parent and (value is None or extend):
|
||||
# If parent is static, we can grab attrs from the parent
|
||||
# otherwise, defer to the grandparent
|
||||
if getattr(self._parent, 'statically_loaded', True):
|
||||
_parent = self._parent
|
||||
else:
|
||||
_parent = self._parent._parent
|
||||
|
||||
if _parent and (value is None or extend):
|
||||
try:
|
||||
if getattr(self._parent, 'statically_loaded', True):
|
||||
if hasattr(self._parent, '_get_parent_attribute'):
|
||||
parent_value = self._parent._get_parent_attribute(attr)
|
||||
if getattr(_parent, 'statically_loaded', True):
|
||||
if hasattr(_parent, '_get_parent_attribute'):
|
||||
parent_value = _parent._get_parent_attribute(attr)
|
||||
else:
|
||||
parent_value = self._parent._attributes.get(attr, None)
|
||||
parent_value = _parent._attributes.get(attr, None)
|
||||
if extend:
|
||||
value = self._extend_value(value, parent_value, prepend)
|
||||
else:
|
||||
|
||||
@@ -48,8 +48,6 @@ class IncludeRole(TaskInclude):
|
||||
OTHER_ARGS = ('private', 'allow_duplicates') # assigned to matching property
|
||||
VALID_ARGS = tuple(frozenset(BASE + FROM_ARGS + OTHER_ARGS)) # all valid args
|
||||
|
||||
_inheritable = False
|
||||
|
||||
# =================================================================================
|
||||
# ATTRIBUTES
|
||||
|
||||
|
||||
@@ -423,13 +423,20 @@ class Task(Base, Conditional, Taggable, Become):
|
||||
prepend = self._valid_attrs[attr].prepend
|
||||
try:
|
||||
value = self._attributes[attr]
|
||||
if self._parent and (value is None or extend):
|
||||
if getattr(self._parent, 'statically_loaded', True):
|
||||
# If parent is static, we can grab attrs from the parent
|
||||
# otherwise, defer to the grandparent
|
||||
if getattr(self._parent, 'statically_loaded', True):
|
||||
_parent = self._parent
|
||||
else:
|
||||
_parent = self._parent._parent
|
||||
|
||||
if _parent and (value is None or extend):
|
||||
if getattr(_parent, 'statically_loaded', True):
|
||||
# vars are always inheritable, other attributes might not be for the partent but still should be for other ancestors
|
||||
if attr != 'vars' and getattr(self._parent, '_inheritable', True) and hasattr(self._parent, '_get_parent_attribute'):
|
||||
parent_value = self._parent._get_parent_attribute(attr)
|
||||
if attr != 'vars' and hasattr(_parent, '_get_parent_attribute'):
|
||||
parent_value = _parent._get_parent_attribute(attr)
|
||||
else:
|
||||
parent_value = self._parent._attributes.get(attr, None)
|
||||
parent_value = _parent._attributes.get(attr, None)
|
||||
|
||||
if extend:
|
||||
value = self._extend_value(value, parent_value, prepend)
|
||||
|
||||
@@ -50,8 +50,6 @@ class TaskInclude(Task):
|
||||
@staticmethod
|
||||
def load(data, block=None, role=None, task_include=None, variable_manager=None, loader=None):
|
||||
t = TaskInclude(block=block, role=role, task_include=task_include)
|
||||
if t.action == 'include_task':
|
||||
t._inheritable = False
|
||||
return t.load_data(data, variable_manager=variable_manager, loader=loader)
|
||||
|
||||
def copy(self, exclude_parent=False, exclude_tasks=False):
|
||||
|
||||
Reference in New Issue
Block a user