From fad44862a58f3100775d1f6e3aa31c3863324883 Mon Sep 17 00:00:00 2001 From: James Cammarata Date: Wed, 5 Aug 2015 11:52:52 -0400 Subject: [PATCH] Implementing includes in the free strategy --- lib/ansible/plugins/strategies/free.py | 27 ++++++++++++++++++++++++ lib/ansible/plugins/strategies/linear.py | 2 +- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/lib/ansible/plugins/strategies/free.py b/lib/ansible/plugins/strategies/free.py index ea894c5bf6..43b6296473 100644 --- a/lib/ansible/plugins/strategies/free.py +++ b/lib/ansible/plugins/strategies/free.py @@ -21,6 +21,8 @@ __metaclass__ = type import time +from ansible.errors import * +from ansible.playbook.included_file import IncludedFile from ansible.plugins.strategies import StrategyBase try: @@ -140,6 +142,31 @@ class StrategyModule(StrategyBase): results = self._process_pending_results(iterator) host_results.extend(results) + try: + included_files = IncludedFile.process_include_results(host_results, self._tqm, iterator=iterator, loader=self._loader, variable_manager=self._variable_manager) + except AnsibleError, e: + return False + + if len(included_files) > 0: + for included_file in included_files: + # 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) + except AnsibleError, e: + for host in included_file._hosts: + iterator.mark_host_failed(host) + self._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) + # pause briefly so we don't spin lock time.sleep(0.05) diff --git a/lib/ansible/plugins/strategies/linear.py b/lib/ansible/plugins/strategies/linear.py index 6de217f3f1..feac091766 100644 --- a/lib/ansible/plugins/strategies/linear.py +++ b/lib/ansible/plugins/strategies/linear.py @@ -194,8 +194,8 @@ class StrategyModule(StrategyBase): if self._take_step(task): choose_step = False else: - break skip_rest = True + break self._display.debug("getting variables") task_vars = self._variable_manager.get_vars(loader=self._loader, play=iterator._play, host=host, task=task)