diff --git a/lib/ansible/plugins/strategy/free.py b/lib/ansible/plugins/strategy/free.py index 48c9b3aa9a9..74ac9743b7f 100644 --- a/lib/ansible/plugins/strategy/free.py +++ b/lib/ansible/plugins/strategy/free.py @@ -23,7 +23,9 @@ import time from ansible.errors import AnsibleError from ansible.playbook.included_file import IncludedFile +from ansible.plugins import action_loader from ansible.plugins.strategy import StrategyBase +from ansible.template import Templar try: from __main__ import display @@ -92,10 +94,28 @@ class StrategyModule(StrategyBase): self._blocked_hosts[host_name] = True (state, task) = iterator.get_next_task_for_host(host) + try: + action = action_loader.get(task.action, class_only=True) + except KeyError: + # we don't care here, because the action may simply not have a + # corresponding action plugin + action = None + display.debug("getting variables") task_vars = self._variable_manager.get_vars(loader=self._loader, play=iterator._play, host=host, task=task) + self.add_tqm_variables(task_vars, play=iterator._play) + templar = Templar(loader=self._loader, variables=task_vars) display.debug("done getting variables") + run_once = templar.template(task.run_once) or action and getattr(action, 'BYPASS_HOST_LOOP', False) + if run_once: + if action and getattr(action, 'BYPASS_HOST_LOOP', False): + raise AnsibleError("The '%s' module bypasses the host loop, which is currently not supported in the free strategy " \ + "and would instead execute for every host in the inventory list." % task.action, obj=task._ds) + else: + display.warning("Using run_once with the free strategy is not currently supported. This task will still be " \ + "executed for every host in the inventory list.") + # check to see if this task should be skipped, due to it being a member of a # role which has already run (and whether that role allows duplicate execution) if task._role and task._role.has_run(host): diff --git a/lib/ansible/plugins/strategy/linear.py b/lib/ansible/plugins/strategy/linear.py index b413e526ebf..0d4faf61493 100644 --- a/lib/ansible/plugins/strategy/linear.py +++ b/lib/ansible/plugins/strategy/linear.py @@ -199,7 +199,7 @@ class StrategyModule(StrategyBase): except KeyError: # we don't care here, because the action may simply not have a # corresponding action plugin - pass + action = None # check to see if this task should be skipped, due to it being a member of a # role which has already run (and whether that role allows duplicate execution) @@ -227,7 +227,7 @@ class StrategyModule(StrategyBase): templar = Templar(loader=self._loader, variables=task_vars) display.debug("done getting variables") - run_once = templar.template(task.run_once) or getattr(action, 'BYPASS_HOST_LOOP', False) + run_once = templar.template(task.run_once) or action and getattr(action, 'BYPASS_HOST_LOOP', False) if task.any_errors_fatal or run_once: any_errors_fatal = True