Skip to content

Commit

Permalink
Fix conditional inheritance on dynamic includes (tasks and roles) (an…
Browse files Browse the repository at this point in the history
…sible#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 ansible#27845
  • Loading branch information
jimi-c authored Sep 13, 2017
1 parent b2ac60c commit b38f746
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 10 deletions.
19 changes: 14 additions & 5 deletions lib/ansible/playbook/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,11 +294,12 @@ def _get_parent_attribute(self, attr, extend=False, prepend=False):

if self._parent and (value is None or extend):
try:
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 AttributeError:
pass
if self._role and (value is None or extend):
Expand Down Expand Up @@ -386,3 +387,11 @@ def all_parents_static(self):
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
4 changes: 4 additions & 0 deletions lib/ansible/playbook/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ def load_list_of_tasks(ds, play, block=None, role=None, task_include=None, use_h
else:
task_list.extend(included_blocks)
else:
t.is_static = False
task_list.append(t)

elif 'include_role' in task_ds or 'import_role' in task_ds:
Expand Down Expand Up @@ -319,6 +320,9 @@ def load_list_of_tasks(ds, play, block=None, role=None, task_include=None, use_h
display.debug('Determined that if include_role static is %s' % str(is_static))

if is_static:
# we set a flag to indicate this include was static
ir.statically_loaded = True

# uses compiled list from object
blocks, _ = ir.get_block_list(variable_manager=variable_manager, loader=loader)
t = task_list.extend(blocks)
Expand Down
19 changes: 14 additions & 5 deletions lib/ansible/playbook/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,11 +411,12 @@ def _get_parent_attribute(self, attr, extend=False, prepend=False):
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

Expand Down Expand Up @@ -456,3 +457,11 @@ def all_parents_static(self):
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

0 comments on commit b38f746

Please sign in to comment.