From 9b61cf5840fd1bce8bd4e320feaae5da73507f9e Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Sun, 16 Aug 2015 20:05:10 -0400 Subject: [PATCH] implemented async tasks in adhoc v2 --- lib/ansible/cli/__init__.py | 3 +-- lib/ansible/cli/adhoc.py | 15 +++------------ 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/lib/ansible/cli/__init__.py b/lib/ansible/cli/__init__.py index f21d3528f36..eaeccf14584 100644 --- a/lib/ansible/cli/__init__.py +++ b/lib/ansible/cli/__init__.py @@ -308,8 +308,7 @@ class CLI(object): help="override the connection timeout in seconds (default=%s)" % C.DEFAULT_TIMEOUT) if async_opts: - parser.add_option('-P', '--poll', default=C.DEFAULT_POLL_INTERVAL, type='int', - dest='poll_interval', + parser.add_option('-P', '--poll', default=C.DEFAULT_POLL_INTERVAL, type='int', dest='poll_interval', help="set the poll interval if using -B (default=%s)" % C.DEFAULT_POLL_INTERVAL) parser.add_option('-B', '--background', dest='seconds', type='int', default=0, help='run asynchronously, failing after X seconds (default=N/A)') diff --git a/lib/ansible/cli/adhoc.py b/lib/ansible/cli/adhoc.py index 20e160274f7..cb93e1a36ec 100644 --- a/lib/ansible/cli/adhoc.py +++ b/lib/ansible/cli/adhoc.py @@ -64,12 +64,12 @@ class AdHocCLI(CLI): return True - def _play_ds(self, pattern): + def _play_ds(self, pattern, async, poll): return dict( name = "Ansible Ad-Hoc", hosts = pattern, gather_facts = 'no', - tasks = [ dict(action=dict(module=self.options.module_name, args=parse_kv(self.options.module_args))), ] + tasks = [ dict(action=dict(module=self.options.module_name, args=parse_kv(self.options.module_args)), async=async, poll=poll) ] ) def run(self): @@ -122,16 +122,7 @@ class AdHocCLI(CLI): err = err + ' (did you mean to run ansible-playbook?)' raise AnsibleOptionsError(err) - #TODO: implement async support - #if self.options.seconds: - # callbacks.display("background launch...\n\n", color='cyan') - # results, poller = runner.run_async(self.options.seconds) - # results = self.poll_while_needed(poller) - #else: - # results = runner.run() - - # create a pseudo-play to execute the specified module via a single task - play_ds = self._play_ds(pattern) + play_ds = self._play_ds(pattern, self.options.seconds, self.options.poll_interval) play = Play().load(play_ds, variable_manager=variable_manager, loader=loader) if self.options.one_line: