diff --git a/lib/ansible/playbook/included_file.py b/lib/ansible/playbook/included_file.py index 6fc3bd5cbf..b7c0fb8175 100644 --- a/lib/ansible/playbook/included_file.py +++ b/lib/ansible/playbook/included_file.py @@ -24,6 +24,12 @@ import os from ansible.errors import AnsibleError from ansible.template import Templar +try: + from __main__ import display +except ImportError: + from ansible.utils.display import Display + display = Display() + class IncludedFile: def __init__(self, filename, args, task): diff --git a/lib/ansible/plugins/strategy/__init__.py b/lib/ansible/plugins/strategy/__init__.py index f1f4650529..38c65552d3 100644 --- a/lib/ansible/plugins/strategy/__init__.py +++ b/lib/ansible/plugins/strategy/__init__.py @@ -414,6 +414,7 @@ class StrategyBase: Loads an included YAML file of tasks, applying the optional set of variables. ''' + display.debug("loading included file: %s" % included_file._filename) try: data = self._loader.load_from_file(included_file._filename) if data is None: @@ -474,6 +475,7 @@ class StrategyBase: # finally, send the callback and return the list of blocks loaded self._tqm.send_callback('v2_playbook_on_include', included_file) + display.debug("done processing included file") return block_list def run_handlers(self, iterator, play_context): diff --git a/lib/ansible/plugins/strategy/free.py b/lib/ansible/plugins/strategy/free.py index 2d3c184a8c..e83184891d 100644 --- a/lib/ansible/plugins/strategy/free.py +++ b/lib/ansible/plugins/strategy/free.py @@ -156,13 +156,18 @@ class StrategyModule(StrategyBase): display.warning(str(e)) continue - for host in hosts_left: - if host in included_file._hosts: - task_vars = self._variable_manager.get_vars(loader=self._loader, play=iterator._play, host=host, task=included_file._task) - final_blocks = [] - for new_block in new_blocks: - final_blocks.append(new_block.filter_tagged_tasks(play_context, task_vars)) - iterator.add_tasks(host, final_blocks) + display.debug("generating all_blocks data") + all_blocks = dict((host, []) for host in hosts_left) + display.debug("done generating all_blocks data") + for new_block in new_blocks: + task_vars = self._variable_manager.get_vars(loader=self._loader, play=iterator._play, task=included_file._task) + final_block = new_block.filter_tagged_tasks(play_context, task_vars) + for host in hosts_left: + if host in included_file._hosts: + all_blocks[host].append(final_block) + + for host in hosts_left: + iterator.add_tasks(host, all_blocks[host]) # pause briefly so we don't spin lock time.sleep(0.05) diff --git a/lib/ansible/plugins/strategy/linear.py b/lib/ansible/plugins/strategy/linear.py index 65240ef8fa..8a8d5c084a 100644 --- a/lib/ansible/plugins/strategy/linear.py +++ b/lib/ansible/plugins/strategy/linear.py @@ -264,31 +264,44 @@ class StrategyModule(StrategyBase): return False if len(included_files) > 0: + display.debug("we have included files to process") noop_task = Task() noop_task.action = 'meta' noop_task.args['_raw_params'] = 'noop' noop_task.set_loader(iterator._play._loader) + display.debug("generating all_blocks data") all_blocks = dict((host, []) for host in hosts_left) + display.debug("done generating all_blocks data") for included_file in included_files: + display.debug("processing included file: %s" % included_file._filename) # 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) + display.debug("iterating over new_blocks loaded from include file") for new_block in new_blocks: + task_vars = self._variable_manager.get_vars( + loader=self._loader, + play=iterator._play, + task=included_file._task, + ) + display.debug("filtering new block on tags") + final_block = new_block.filter_tagged_tasks(play_context, task_vars) + display.debug("done filtering new block on tags") + noop_block = Block(parent_block=task._block) noop_block.block = [noop_task for t in new_block.block] noop_block.always = [noop_task for t in new_block.always] noop_block.rescue = [noop_task for t in new_block.rescue] + for host in hosts_left: if host in included_file._hosts: - task_vars = self._variable_manager.get_vars(loader=self._loader, - play=iterator._play, host=host, task=included_file._task) - final_block = new_block.filter_tagged_tasks(play_context, task_vars) all_blocks[host].append(final_block) else: all_blocks[host].append(noop_block) + display.debug("done iterating over new_blocks loaded from include file") except AnsibleError as e: for host in included_file._hosts: @@ -299,9 +312,14 @@ class StrategyModule(StrategyBase): # finally go through all of the hosts and append the # accumulated blocks to their list of tasks + display.debug("extending task lists for all hosts with included blocks") + for host in hosts_left: iterator.add_tasks(host, all_blocks[host]) + display.debug("done extending task lists") + display.debug("done processing included files") + display.debug("results queue empty") except (IOError, EOFError) as e: display.debug("got IOError/EOFError in task loop: %s" % e)