mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-08 06:12:51 +00:00
implemented async tasks in adhoc v2
This commit is contained in:
@@ -308,8 +308,7 @@ class CLI(object):
|
|||||||
help="override the connection timeout in seconds (default=%s)" % C.DEFAULT_TIMEOUT)
|
help="override the connection timeout in seconds (default=%s)" % C.DEFAULT_TIMEOUT)
|
||||||
|
|
||||||
if async_opts:
|
if async_opts:
|
||||||
parser.add_option('-P', '--poll', default=C.DEFAULT_POLL_INTERVAL, type='int',
|
parser.add_option('-P', '--poll', default=C.DEFAULT_POLL_INTERVAL, type='int', dest='poll_interval',
|
||||||
dest='poll_interval',
|
|
||||||
help="set the poll interval if using -B (default=%s)" % C.DEFAULT_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,
|
parser.add_option('-B', '--background', dest='seconds', type='int', default=0,
|
||||||
help='run asynchronously, failing after X seconds (default=N/A)')
|
help='run asynchronously, failing after X seconds (default=N/A)')
|
||||||
|
|||||||
@@ -64,12 +64,12 @@ class AdHocCLI(CLI):
|
|||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def _play_ds(self, pattern):
|
def _play_ds(self, pattern, async, poll):
|
||||||
return dict(
|
return dict(
|
||||||
name = "Ansible Ad-Hoc",
|
name = "Ansible Ad-Hoc",
|
||||||
hosts = pattern,
|
hosts = pattern,
|
||||||
gather_facts = 'no',
|
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):
|
def run(self):
|
||||||
@@ -122,16 +122,7 @@ class AdHocCLI(CLI):
|
|||||||
err = err + ' (did you mean to run ansible-playbook?)'
|
err = err + ' (did you mean to run ansible-playbook?)'
|
||||||
raise AnsibleOptionsError(err)
|
raise AnsibleOptionsError(err)
|
||||||
|
|
||||||
#TODO: implement async support
|
play_ds = self._play_ds(pattern, self.options.seconds, self.options.poll_interval)
|
||||||
#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 = Play().load(play_ds, variable_manager=variable_manager, loader=loader)
|
play = Play().load(play_ds, variable_manager=variable_manager, loader=loader)
|
||||||
|
|
||||||
if self.options.one_line:
|
if self.options.one_line:
|
||||||
|
|||||||
Reference in New Issue
Block a user