Make /usr/bin/ansible output realtime and also delete some code!

This commit is contained in:
Michael DeHaan
2012-03-26 21:17:11 -04:00
parent eb67a91c57
commit 45a455a805
4 changed files with 55 additions and 63 deletions

View File

@@ -83,6 +83,31 @@ class DefaultRunnerCallbacks(object):
def on_unreachable(self, host, res):
pass
class CliRunnerCallbacks(DefaultRunnerCallbacks):
def __init__(self):
# set by /usr/bin/ansible later
self.options = None
def on_failed(self, host, res):
self._on_any(host,res)
def on_ok(self, host, res):
self._on_any(host,res)
def on_unreachable(self, host, res):
print "%s | FAILED => %s" % (host, res)
if self.options.tree:
utils.write_tree_file(self.options.tree, host, dict(failed=True, msg=res))
def on_skipped(self, host):
pass
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:
utils.write_tree_file(self.options.tree, host, utils.bigjson(result))
class PlaybookRunnerCallbacks(DefaultRunnerCallbacks):
def __init__(self, stats):

View File

@@ -494,7 +494,10 @@ class Runner(object):
def _executor(self, host):
try:
return self._executor_internal(host)
(host, ok, data) = self._executor_internal(host)
if not ok:
self.callbacks.on_unreachable(host, data)
return (host, ok, data)
except errors.AnsibleError, ae:
msg = str(ae)
self.callbacks.on_unreachable(host, msg)

View File

@@ -135,7 +135,7 @@ def host_report_msg(hostname, module_name, result, oneline):
''' summarize the JSON results for a particular host '''
buf = ''
failed = is_failed(result)
if module_name in [ 'command', 'shell' ]:
if module_name in [ 'command', 'shell' ] and 'ansible_job_id' not in result:
if not failed:
buf = command_success_msg(hostname, result, oneline)
else:
@@ -147,15 +147,7 @@ def host_report_msg(hostname, module_name, result, oneline):
buf = regular_failure_msg(hostname, result, oneline)
return buf
def dark_hosts_msg(results):
''' summarize the results of all uncontactable hosts '''
buf = ''
if len(results['dark'].keys()) > 0:
buf += "\n*** Hosts with fatal errors: ***\n"
for hostname in results['dark'].keys():
buf += "%s: %s\n" % (hostname, results['dark'][hostname])
buf += "\n"
return buf
# FIXME: needed? ... may be able to eliminate many of these...
def has_dark_hosts(results):
''' are there any uncontactable hosts? '''