mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-25 22:30:22 -07:00
Introduce Async API in Runner.
This commit is contained in:
parent
d96763346f
commit
ce9a8c9ffc
2 changed files with 120 additions and 10 deletions
|
@ -50,7 +50,7 @@ class AggregateStats(object):
|
|||
elif 'skipped' in value and bool(value['skipped']):
|
||||
self._increment('skipped', host)
|
||||
elif 'changed' in value and bool(value['changed']):
|
||||
if not setup:
|
||||
if not setup and not poll:
|
||||
self._increment('changed', host)
|
||||
self._increment('ok', host)
|
||||
else:
|
||||
|
@ -98,6 +98,15 @@ class DefaultRunnerCallbacks(object):
|
|||
def on_no_hosts(self):
|
||||
pass
|
||||
|
||||
def on_async_poll(self, host, res, jid, clock):
|
||||
pass
|
||||
|
||||
def on_async_ok(self, host, res, jid):
|
||||
pass
|
||||
|
||||
def on_async_failed(self, host, res, jid):
|
||||
pass
|
||||
|
||||
########################################################################
|
||||
|
||||
class CliRunnerCallbacks(DefaultRunnerCallbacks):
|
||||
|
@ -108,10 +117,14 @@ class CliRunnerCallbacks(DefaultRunnerCallbacks):
|
|||
self.options = None
|
||||
|
||||
def on_failed(self, host, res):
|
||||
self._on_any(host,res)
|
||||
invocation = res.get('invocation','')
|
||||
if not invocation.startswith('async_status'):
|
||||
self._on_any(host,res)
|
||||
|
||||
def on_ok(self, host, res):
|
||||
self._on_any(host,res)
|
||||
invocation = res.get('invocation','')
|
||||
if not invocation.startswith('async_status'):
|
||||
self._on_any(host,res)
|
||||
|
||||
def on_unreachable(self, host, res):
|
||||
print "%s | FAILED => %s" % (host, res)
|
||||
|
@ -127,6 +140,15 @@ class CliRunnerCallbacks(DefaultRunnerCallbacks):
|
|||
def on_no_hosts(self):
|
||||
print >>sys.stderr, "no hosts matched\n"
|
||||
|
||||
def on_async_poll(self, host, res, jid, clock):
|
||||
print "<job %s> polling on %s, %s remaining"%(jid, host, clock)
|
||||
|
||||
def on_async_ok(self, host, res, jid):
|
||||
print "<job %s> finished on %s => %s"%(jid, host, utils.bigjson(res))
|
||||
|
||||
def on_async_failed(self, host, res, jid):
|
||||
print "<job %s> FAILED on %s => %s"%(jid, host, utils.bigjson(res))
|
||||
|
||||
def _on_any(self, host, result):
|
||||
print utils.host_report_msg(host, self.options.module_name, result, self.options.one_line)
|
||||
if self.options.tree:
|
||||
|
@ -168,6 +190,15 @@ class PlaybookRunnerCallbacks(DefaultRunnerCallbacks):
|
|||
def on_no_hosts(self):
|
||||
print "no hosts matched or remaining\n"
|
||||
|
||||
def on_async_poll(self, host, res, jid, clock):
|
||||
print "<job %s> polling on %s, %s remaining"%(jid, host, clock)
|
||||
|
||||
def on_async_ok(self, host, res, jid):
|
||||
print "<job %s> finished on %s"%(jid, host)
|
||||
|
||||
def on_async_failed(self, host, res, jid):
|
||||
print "<job %s> FAILED on %s"%(jid, host)
|
||||
|
||||
########################################################################
|
||||
|
||||
class PlaybookCallbacks(object):
|
||||
|
@ -205,10 +236,3 @@ class PlaybookCallbacks(object):
|
|||
|
||||
def on_play_start(self, pattern):
|
||||
print "PLAY [%s] ****************************\n" % pattern
|
||||
|
||||
def on_async_confused(self, msg):
|
||||
print msg
|
||||
|
||||
def on_async_poll(self, jid, host, clock, host_result):
|
||||
print utils.async_poll_status(jid, host, clock, host_result)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue