Make include_x inheritance more congruent with docs (#32769)
* draft making tags congruent with include_x * remove ability to 'inline tags' for new inc keys * generic inheritance * fix typo * pepe
This commit is contained in:
parent
e499bccbaa
commit
8e6ebae8bd
6 changed files with 17 additions and 5 deletions
|
@ -165,6 +165,8 @@ class Base(with_metaclass(BaseMeta, object)):
|
||||||
'su', 'su_user', 'su_pass', 'su_exe', 'su_flags',
|
'su', 'su_user', 'su_pass', 'su_exe', 'su_flags',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
_inheritable = True
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
|
||||||
# initialize the data loader and variable manager, which will be provided
|
# initialize the data loader and variable manager, which will be provided
|
||||||
|
|
|
@ -249,6 +249,7 @@ def load_list_of_tasks(ds, play, block=None, role=None, task_include=None, use_h
|
||||||
variable_manager=variable_manager,
|
variable_manager=variable_manager,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# FIXME: remove once 'include' is removed
|
||||||
# pop tags out of the include args, if they were specified there, and assign
|
# pop tags out of the include args, if they were specified there, and assign
|
||||||
# them to the include. If the include already had tags specified, we raise an
|
# them to the include. If the include already had tags specified, we raise an
|
||||||
# error so that users know not to specify them both ways
|
# error so that users know not to specify them both ways
|
||||||
|
@ -257,6 +258,8 @@ def load_list_of_tasks(ds, play, block=None, role=None, task_include=None, use_h
|
||||||
tags = tags.split(',')
|
tags = tags.split(',')
|
||||||
|
|
||||||
if len(tags) > 0:
|
if len(tags) > 0:
|
||||||
|
if 'include_tasks' in task_ds or 'import_tasks' in task_ds:
|
||||||
|
raise AnsibleParserError('You cannot specify "tags" inline to the task, it is a task keyword')
|
||||||
if len(ti_copy.tags) > 0:
|
if len(ti_copy.tags) > 0:
|
||||||
raise AnsibleParserError(
|
raise AnsibleParserError(
|
||||||
"Include tasks should not specify tags in more than one way (both via args and directly on the task). "
|
"Include tasks should not specify tags in more than one way (both via args and directly on the task). "
|
||||||
|
|
|
@ -48,6 +48,8 @@ class IncludeRole(TaskInclude):
|
||||||
OTHER_ARGS = ('private', 'allow_duplicates') # assigned to matching property
|
OTHER_ARGS = ('private', 'allow_duplicates') # assigned to matching property
|
||||||
VALID_ARGS = tuple(frozenset(BASE + FROM_ARGS + OTHER_ARGS)) # all valid args
|
VALID_ARGS = tuple(frozenset(BASE + FROM_ARGS + OTHER_ARGS)) # all valid args
|
||||||
|
|
||||||
|
_inheritable = False
|
||||||
|
|
||||||
# =================================================================================
|
# =================================================================================
|
||||||
# ATTRIBUTES
|
# ATTRIBUTES
|
||||||
|
|
||||||
|
|
|
@ -49,11 +49,9 @@ class Taggable:
|
||||||
|
|
||||||
def _get_attr_tags(self):
|
def _get_attr_tags(self):
|
||||||
'''
|
'''
|
||||||
Override for the 'tags' getattr fetcher, used from Base.
|
Override for the 'tags' getattr fetcher, used from Base, allow some classes to not give their tags to their 'children'
|
||||||
'''
|
'''
|
||||||
tags = self._attributes['tags']
|
tags = self._attributes.get('tags', [])
|
||||||
if tags is None:
|
|
||||||
tags = []
|
|
||||||
if hasattr(self, '_get_parent_attribute'):
|
if hasattr(self, '_get_parent_attribute'):
|
||||||
tags = self._get_parent_attribute('tags', extend=True)
|
tags = self._get_parent_attribute('tags', extend=True)
|
||||||
return tags
|
return tags
|
||||||
|
|
|
@ -420,7 +420,12 @@ class Task(Base, Conditional, Taggable, Become):
|
||||||
value = self._attributes[attr]
|
value = self._attributes[attr]
|
||||||
if self._parent and (value is None or extend):
|
if self._parent and (value is None or extend):
|
||||||
if attr != 'when' or getattr(self._parent, 'statically_loaded', True):
|
if attr != 'when' or getattr(self._parent, 'statically_loaded', True):
|
||||||
parent_value = getattr(self._parent, attr, None)
|
# vars are always inheritable, other attributes might not be for the partent but still should be for other ancestors
|
||||||
|
if attr != 'vars' and not getattr(self._parent, '_inheritable', True) and hasattr(self._parent, '_get_parent_attribute'):
|
||||||
|
parent_value = self._parent._get_parent_attribute(attr, extend=extend, prepend=prepend)
|
||||||
|
else:
|
||||||
|
parent_value = getattr(self._parent, attr, None)
|
||||||
|
|
||||||
if extend:
|
if extend:
|
||||||
value = self._extend_value(value, parent_value, prepend)
|
value = self._extend_value(value, parent_value, prepend)
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -50,6 +50,8 @@ class TaskInclude(Task):
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def load(data, block=None, role=None, task_include=None, variable_manager=None, loader=None):
|
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)
|
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)
|
return t.load_data(data, variable_manager=variable_manager, loader=loader)
|
||||||
|
|
||||||
def copy(self, exclude_parent=False, exclude_tasks=False):
|
def copy(self, exclude_parent=False, exclude_tasks=False):
|
||||||
|
|
Loading…
Reference in a new issue