mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-22 04:40:22 -07:00
Dynamic role include (#17401)
* dynamic role_include * more fixes for dynamic include roles * set play yfrom iterator when dynamic * changes from jimi-c * avoid modules that break ad hoc TODO: should really be a config
This commit is contained in:
parent
d5aecfdd14
commit
ff34f5548d
9 changed files with 148 additions and 49 deletions
|
@ -376,7 +376,7 @@ class StrategyBase:
|
|||
if self._diff:
|
||||
self._tqm.send_callback('v2_on_file_diff', task_result)
|
||||
|
||||
if original_task.action != 'include':
|
||||
if original_task.action in ['include', 'include_role']:
|
||||
self._tqm._stats.increment('ok', original_host.name)
|
||||
if 'changed' in task_result._result and task_result._result['changed']:
|
||||
self._tqm._stats.increment('changed', original_host.name)
|
||||
|
@ -390,7 +390,7 @@ class StrategyBase:
|
|||
|
||||
# If this is a role task, mark the parent role as being run (if
|
||||
# the task was ok or failed, but not skipped or unreachable)
|
||||
if original_task._role is not None and role_ran and original_task.action != 'include_role':
|
||||
if original_task._role is not None and role_ran: #TODO: and original_task.action != 'include_role':?
|
||||
# lookup the role in the ROLE_CACHE to make sure we're dealing
|
||||
# with the correct object and mark it as executed
|
||||
for (entry, role_obj) in iteritems(iterator._play.ROLE_CACHE[original_task._role._role_name]):
|
||||
|
|
|
@ -280,6 +280,36 @@ class StrategyModule(StrategyBase):
|
|||
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['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
|
||||
|
||||
role_vars = include_result.get('include_variables', dict())
|
||||
if loop_var and loop_var in include_result:
|
||||
role_vars[loop_var] = include_result[loop_var]
|
||||
|
||||
display.debug("generating all_blocks data for role")
|
||||
new_ir = hr._task.copy()
|
||||
new_ir.args.update(role_vars)
|
||||
all_role_blocks.extend(new_ir.get_block_list(play=iterator._play, variable_manager=self._variable_manager, loader=self._loader))
|
||||
|
||||
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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue