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:
Brian Coca 2017-11-30 17:16:10 -05:00 committed by James Cammarata
parent e499bccbaa
commit 8e6ebae8bd
6 changed files with 17 additions and 5 deletions

View file

@ -165,6 +165,8 @@ 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

View file

@ -249,6 +249,7 @@ def load_list_of_tasks(ds, play, block=None, role=None, task_include=None, use_h
variable_manager=variable_manager,
)
# FIXME: remove once 'include' is removed
# 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
# 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(',')
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:
raise AnsibleParserError(
"Include tasks should not specify tags in more than one way (both via args and directly on the task). "

View file

@ -48,6 +48,8 @@ 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

View file

@ -49,11 +49,9 @@ class Taggable:
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']
if tags is None:
tags = []
tags = self._attributes.get('tags', [])
if hasattr(self, '_get_parent_attribute'):
tags = self._get_parent_attribute('tags', extend=True)
return tags

View file

@ -420,7 +420,12 @@ class Task(Base, Conditional, Taggable, Become):
value = self._attributes[attr]
if self._parent and (value is None or extend):
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:
value = self._extend_value(value, parent_value, prepend)
else:

View file

@ -50,6 +50,8 @@ 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):