Address memory ballooning caused by task caching changes (#35921)

* Exclude parent when copying included task to avoid memory issues. Fixes #35796

* Simplify implicit block squashing to pre-group, instead of post re-parenting
This commit is contained in:
Matt Martz 2018-02-08 17:28:07 -06:00 committed by Matt Davis
parent b6dc27249a
commit 7d1eb88ecf
2 changed files with 31 additions and 21 deletions

View file

@ -48,29 +48,38 @@ def load_list_of_blocks(ds, play, parent_block=None, role=None, task_include=Non
block_list = [] block_list = []
if ds: if ds:
for block_ds in ds: count = iter(range(len(ds)))
b = Block.load( for i in count:
block_ds, block_ds = ds[i]
play=play,
parent_block=parent_block,
role=role,
task_include=task_include,
use_handlers=use_handlers,
variable_manager=variable_manager,
loader=loader,
)
# Implicit blocks are created by bare tasks listed in a play without # Implicit blocks are created by bare tasks listed in a play without
# an explicit block statement. If we have two implicit blocks in a row, # an explicit block statement. If we have two implicit blocks in a row,
# squash them down to a single block to save processing time later. # squash them down to a single block to save processing time later.
if b._implicit and len(block_list) > 0 and block_list[-1]._implicit: implicit_blocks = []
for t in b.block: while block_ds is not None and not Block.is_block(block_ds):
if isinstance(t._parent, (TaskInclude, IncludeRole)): implicit_blocks.append(block_ds)
t._parent._parent = block_list[-1] i += 1
else: # Advance the iterator, so we don't repeat
t._parent = block_list[-1] next(count, None)
block_list[-1].block.extend(b.block) try:
else: block_ds = ds[i]
block_list.append(b) except IndexError:
block_ds = None
# Loop both implicit blocks and block_ds as block_ds is the next in the list
for b in (implicit_blocks, block_ds):
if b:
block_list.append(
Block.load(
b,
play=play,
parent_block=parent_block,
role=role,
task_include=task_include,
use_handlers=use_handlers,
variable_manager=variable_manager,
loader=loader,
)
)
return block_list return block_list

View file

@ -763,7 +763,8 @@ class StrategyBase:
elif not isinstance(data, list): elif not isinstance(data, list):
raise AnsibleError("included task files must contain a list of tasks") raise AnsibleError("included task files must contain a list of tasks")
ti_copy = included_file._task.copy() ti_copy = included_file._task.copy(exclude_parent=True)
ti_copy._parent = included_file._task._parent
temp_vars = ti_copy.vars.copy() temp_vars = ti_copy.vars.copy()
temp_vars.update(included_file._args) temp_vars.update(included_file._args)
# pop tags out of the include args, if they were specified there, and assign # pop tags out of the include args, if they were specified there, and assign