mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-24 19:31:26 -07:00
Correctly create include_role blocks when using loops (#30372)
Also fixes instances where conditionals or other variables may result in hosts executing lists of tasks of differing sizes. Fixes #18748
This commit is contained in:
parent
173c41aefe
commit
6730f81024
3 changed files with 74 additions and 76 deletions
|
@ -290,39 +290,9 @@ class StrategyModule(StrategyBase):
|
|||
display.debug("done queuing things up, now waiting for results queue to drain")
|
||||
if self._pending_results > 0:
|
||||
results += self._wait_on_pending_results(iterator)
|
||||
|
||||
host_results.extend(results)
|
||||
|
||||
all_role_blocks = []
|
||||
for hr in results:
|
||||
# handle include_role
|
||||
if hr._task.action == 'include_role':
|
||||
loop_var = None
|
||||
if hr._task.loop:
|
||||
loop_var = 'item'
|
||||
if hr._task.loop_control:
|
||||
loop_var = hr._task.loop_control.loop_var or 'item'
|
||||
include_results = hr._result.get('results', [])
|
||||
else:
|
||||
include_results = [hr._result]
|
||||
|
||||
for include_result in include_results:
|
||||
if 'skipped' in include_result and include_result['skipped'] or 'failed' in include_result and include_result['failed']:
|
||||
continue
|
||||
|
||||
display.debug("generating all_blocks data for role")
|
||||
new_ir = hr._task.copy()
|
||||
new_ir.vars.update(include_result.get('include_variables', dict()))
|
||||
if loop_var and loop_var in include_result:
|
||||
new_ir.vars[loop_var] = include_result[loop_var]
|
||||
|
||||
blocks, handler_blocks = new_ir.get_block_list(play=iterator._play, variable_manager=self._variable_manager, loader=self._loader)
|
||||
all_role_blocks.extend(blocks)
|
||||
self._tqm.update_handler_list([handler for handler_block in handler_blocks for handler in handler_block.block])
|
||||
|
||||
if len(all_role_blocks) > 0:
|
||||
for host in hosts_left:
|
||||
iterator.add_tasks(host, all_role_blocks)
|
||||
|
||||
try:
|
||||
included_files = IncludedFile.process_include_results(
|
||||
host_results,
|
||||
|
@ -339,6 +309,8 @@ class StrategyModule(StrategyBase):
|
|||
include_failure = False
|
||||
if len(included_files) > 0:
|
||||
display.debug("we have included files to process")
|
||||
|
||||
# A noop task for use in padding dynamic includes
|
||||
noop_task = Task()
|
||||
noop_task.action = 'meta'
|
||||
noop_task.args['_raw_params'] = 'noop'
|
||||
|
@ -352,7 +324,18 @@ class StrategyModule(StrategyBase):
|
|||
# included hosts get the task list while those excluded get an equal-length
|
||||
# list of noop tasks, to make sure that they continue running in lock-step
|
||||
try:
|
||||
new_blocks = self._load_included_file(included_file, iterator=iterator)
|
||||
if included_file._is_role:
|
||||
new_ir = included_file._task.copy()
|
||||
new_ir.vars.update(included_file._args)
|
||||
|
||||
new_blocks, handler_blocks = new_ir.get_block_list(
|
||||
play=iterator._play,
|
||||
variable_manager=self._variable_manager,
|
||||
loader=self._loader,
|
||||
)
|
||||
self._tqm.update_handler_list([handler for handler_block in handler_blocks for handler in handler_block.block])
|
||||
else:
|
||||
new_blocks = self._load_included_file(included_file, iterator=iterator)
|
||||
|
||||
display.debug("iterating over new_blocks loaded from include file")
|
||||
for new_block in new_blocks:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue