Fix conditional inheritance on dynamic includes (tasks and roles) (#30178)

Per the new style of execution, for dynamic tasks conditionals are expected
to only affect the include task itself and should not be inherited by child
tasks. This patch brings the behavior inline with this expectation.

Fixes #27845
This commit is contained in:
James Cammarata 2017-09-13 11:33:43 -05:00 committed by GitHub
commit b38f746604
3 changed files with 32 additions and 10 deletions

View file

@ -411,11 +411,12 @@ class Task(Base, Conditional, Taggable, Become):
try:
value = self._attributes[attr]
if self._parent and (value is None or extend):
parent_value = getattr(self._parent, attr, None)
if extend:
value = self._extend_value(value, parent_value, prepend)
else:
value = parent_value
if attr != 'when' or getattr(self._parent, 'statically_loaded', True):
parent_value = getattr(self._parent, attr, None)
if extend:
value = self._extend_value(value, parent_value, prepend)
else:
value = parent_value
except KeyError:
pass
@ -456,3 +457,11 @@ class Task(Base, Conditional, Taggable, Become):
if self._parent:
return self._parent.all_parents_static()
return True
def get_first_parent_include(self):
from ansible.playbook.task_include import TaskInclude
if self._parent:
if isinstance(self._parent, TaskInclude):
return self._parent
return self._parent.get_first_parent_include()
return None