Add run_once/BYPASS_HOST_LOOP feature in v2

pull/10388/head
James Cammarata 10 years ago
parent 4af2d0a907
commit f12695f287

@ -359,6 +359,7 @@ class TaskExecutor:
loader=self._loader,
module_loader=self._module_loader,
)
if not handler:
raise AnsibleError("the handler '%s' was not found" % handler_name)

@ -221,6 +221,9 @@ class PluginLoader:
path = self.find_plugin(name)
if path is None:
return None
elif kwargs.get('class_only', False):
return getattr(self._module_cache[path], self.class_name)
if path not in self._module_cache:
self._module_cache[path] = imp.load_source('.'.join([self.package, name]), path)
return getattr(self._module_cache[path], self.class_name)(*args, **kwargs)

@ -22,6 +22,7 @@ __metaclass__ = type
from ansible.errors import AnsibleError
from ansible.executor.play_iterator import PlayIterator
from ansible.playbook.task import Task
from ansible.plugins import action_loader
from ansible.plugins.strategies import StrategyBase
from ansible.utils.debug import debug
@ -143,8 +144,17 @@ class StrategyModule(StrategyBase):
if not task:
continue
run_once = False
work_to_do = True
# test to see if the task across all hosts points to an action plugin which
# sets BYPASS_HOST_LOOP to true, or if it has run_once enabled. If so, we
# will only send this task to the first host in the list.
action = action_loader.get(task.action, class_only=True)
if task.run_once or getattr(action, 'BYPASS_HOST_LOOP', False):
run_once = True
debug("getting variables")
task_vars = self._variable_manager.get_vars(loader=self._loader, play=iterator._play, host=host, task=task)
debug("done getting variables")
@ -183,6 +193,10 @@ class StrategyModule(StrategyBase):
self._process_pending_results(iterator)
# if we're bypassing the host loop, break out now
if run_once:
break
debug("done queuing things up, now waiting for results queue to drain")
self._wait_on_pending_results(iterator)

@ -0,0 +1,6 @@
- hosts: all
gather_facts: no
tasks:
- ping:
run_once: yes
- add_host: name=foo
Loading…
Cancel
Save