Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attempt 4: Prevent reparenting a block with itself #38747

Merged
merged 5 commits into from
Apr 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/ansible/executor/play_iterator.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ def _insert_tasks_into_state(self, state, task_list):
if state.tasks_child_state:
state.tasks_child_state = self._insert_tasks_into_state(state.tasks_child_state, task_list)
else:
target_block = state._blocks[state.cur_block].copy(exclude_parent=True)
target_block = state._blocks[state.cur_block].copy()
before = target_block.block[:state.cur_regular_task]
after = target_block.block[state.cur_regular_task:]
target_block.block = before + task_list + after
Expand All @@ -533,7 +533,7 @@ def _insert_tasks_into_state(self, state, task_list):
if state.rescue_child_state:
state.rescue_child_state = self._insert_tasks_into_state(state.rescue_child_state, task_list)
else:
target_block = state._blocks[state.cur_block].copy(exclude_parent=True)
target_block = state._blocks[state.cur_block].copy()
before = target_block.rescue[:state.cur_rescue_task]
after = target_block.rescue[state.cur_rescue_task:]
target_block.rescue = before + task_list + after
Expand All @@ -542,7 +542,7 @@ def _insert_tasks_into_state(self, state, task_list):
if state.always_child_state:
state.always_child_state = self._insert_tasks_into_state(state.always_child_state, task_list)
else:
target_block = state._blocks[state.cur_block].copy(exclude_parent=True)
target_block = state._blocks[state.cur_block].copy()
before = target_block.always[:state.cur_always_task]
after = target_block.always[state.cur_always_task:]
target_block.always = before + task_list + after
Expand Down
29 changes: 14 additions & 15 deletions lib/ansible/playbook/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ def __eq__(self, other):
'''object comparison based on _uuid'''
return self._uuid == other._uuid

def __ne__(self, other):
'''object comparison based on _uuid'''
return self._uuid != other._uuid

def get_vars(self):
'''
Blocks do not store variables directly, however they may be a member
Expand Down Expand Up @@ -173,21 +177,16 @@ def _dupe_task_list(task_list, new_block):
new_task = task.copy(exclude_parent=True)
if task._parent:
new_task._parent = task._parent.copy(exclude_tasks=True)
# go up the parentage tree until we find an
# object without a parent and make this new
# block their parent
cur_obj = new_task
while cur_obj._parent:
if cur_obj._parent:
prev_obj = cur_obj
cur_obj = cur_obj._parent

# Ensure that we don't make the new_block the parent of itself
if cur_obj != new_block:
cur_obj._parent = new_block
if task._parent == new_block:
# If task._parent is the same as new_block, just replace it
Copy link
Member

@bcoca bcoca Apr 13, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't this a noop?

seems like you jsut want, if task._parent != new_block: and remove up to and including the else:
nvmd

new_task._parent = new_block
else:
# prev_obj._parent is cur_obj, to allow for mutability we need to use prev_obj
prev_obj._parent = new_block
# task may not be a direct child of new_block, search for the correct place to insert new_block
cur_obj = new_task._parent
while cur_obj._parent and cur_obj._parent != new_block:
cur_obj = cur_obj._parent

cur_obj._parent = new_block
else:
new_task._parent = new_block
new_task_list.append(new_task)
Expand All @@ -203,7 +202,7 @@ def _dupe_task_list(task_list, new_block):

new_me._parent = None
if self._parent and not exclude_parent:
new_me._parent = self._parent.copy(exclude_tasks=exclude_tasks)
new_me._parent = self._parent.copy(exclude_tasks=True)

if not exclude_tasks:
new_me.block = _dupe_task_list(self.block or [], new_me)
Expand Down
4 changes: 1 addition & 3 deletions lib/ansible/playbook/role/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,9 +410,7 @@ def compile(self, play, dep_chain=None):
block_list.extend(dep_blocks)

for idx, task_block in enumerate(self._task_blocks):
new_task_block = task_block.copy(exclude_parent=True)
if task_block._parent:
new_task_block._parent = task_block._parent.copy()
new_task_block = task_block.copy()
new_task_block._dep_chain = new_dep_chain
new_task_block._play = play
if idx == len(self._task_blocks) - 1:
Expand Down