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

Prevent reparenting a block with itself #36075

Merged
merged 2 commits into from Feb 13, 2018
Merged
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
14 changes: 13 additions & 1 deletion lib/ansible/playbook/block.py
Expand Up @@ -65,6 +65,10 @@ def __init__(self, play=None, parent_block=None, role=None, task_include=None, u
def __repr__(self):
return "BLOCK(uuid=%s)(id=%s)(parent=%s)" % (self._uuid, id(self), self._parent)

def __eq__(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 @@ -174,8 +178,16 @@ def _dupe_task_list(task_list, new_block):
# block their parent
cur_obj = new_task
while cur_obj._parent:
if cur_obj._parent:
prev_obj = cur_obj
cur_obj = cur_obj._parent
cur_obj._parent = new_block

# Ensure that we don't make the new_block the parent of itself
if cur_obj != new_block:
cur_obj._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
else:
new_task._parent = new_block
new_task_list.append(new_task)
Expand Down