updated with latest changes to default

This commit is contained in:
Brian Coca 2015-11-15 10:09:24 -08:00
parent eeedaf2cbc
commit f1db99caa7

View file

@ -19,6 +19,7 @@
from __future__ import (absolute_import, division, print_function) from __future__ import (absolute_import, division, print_function)
__metaclass__ = type __metaclass__ = type
from ansible import constants as C
from ansible.plugins.callback import CallbackBase from ansible.plugins.callback import CallbackBase
class CallbackModule(CallbackBase): class CallbackModule(CallbackBase):
@ -33,6 +34,7 @@ class CallbackModule(CallbackBase):
CALLBACK_NAME = 'skippy' CALLBACK_NAME = 'skippy'
def v2_runner_on_failed(self, result, ignore_errors=False): def v2_runner_on_failed(self, result, ignore_errors=False):
delegated_vars = result._result.get('_ansible_delegated_vars', None)
if 'exception' in result._result: if 'exception' in result._result:
if self._display.verbosity < 3: if self._display.verbosity < 3:
# extract just the actual error message from the exception text # extract just the actual error message from the exception text
@ -49,8 +51,8 @@ class CallbackModule(CallbackBase):
if result._task.loop and 'results' in result._result: if result._task.loop and 'results' in result._result:
self._process_items(result) self._process_items(result)
else: else:
if result._task.delegate_to: if delegated_vars:
self._display.display("fatal: [%s -> %s]: FAILED! => %s" % (result._host.get_name(), result._task.delegate_to, self._dump_results(result._result)), color='red') self._display.display("fatal: [%s -> %s]: FAILED! => %s" % (result._host.get_name(), delegated_vars['ansible_host'], self._dump_results(result._result)), color='red')
else: else:
self._display.display("fatal: [%s]: FAILED! => %s" % (result._host.get_name(), self._dump_results(result._result)), color='red') self._display.display("fatal: [%s]: FAILED! => %s" % (result._host.get_name(), self._dump_results(result._result)), color='red')
@ -59,18 +61,18 @@ class CallbackModule(CallbackBase):
def v2_runner_on_ok(self, result): def v2_runner_on_ok(self, result):
delegated_vars = result._result.get('_ansible_delegated_vars', None)
if result._task.action == 'include': if result._task.action == 'include':
msg = 'included: %s for %s' % (result._task.args.get('_raw_params'), result._host.name) return
color = 'cyan'
elif result._result.get('changed', False): elif result._result.get('changed', False):
if result._task.delegate_to is not None: if delegated_vars:
msg = "changed: [%s -> %s]" % (result._host.get_name(), result._task.delegate_to) msg = "changed: [%s -> %s]" % (result._host.get_name(), delegated_vars['ansible_host'])
else: else:
msg = "changed: [%s]" % result._host.get_name() msg = "changed: [%s]" % result._host.get_name()
color = 'yellow' color = 'yellow'
else: else:
if result._task.delegate_to is not None: if delegated_vars:
msg = "ok: [%s -> %s]" % (result._host.get_name(), result._task.delegate_to) msg = "ok: [%s -> %s]" % (result._host.get_name(), delegated_vars['ansible_host'])
else: else:
msg = "ok: [%s]" % result._host.get_name() msg = "ok: [%s]" % result._host.get_name()
color = 'green' color = 'green'
@ -79,16 +81,16 @@ class CallbackModule(CallbackBase):
self._process_items(result) self._process_items(result)
else: else:
if (self._display.verbosity > 0 or '_ansible_verbose_always' in result._result) and not '_ansible_verbose_override' in result._result and result._task.action != 'include': if (self._display.verbosity > 0 or '_ansible_verbose_always' in result._result) and not '_ansible_verbose_override' in result._result:
msg += " => %s" % (self._dump_results(result._result),) msg += " => %s" % (self._dump_results(result._result),)
self._display.display(msg, color=color) self._display.display(msg, color=color)
self._handle_warnings(result._result) self._handle_warnings(result._result)
def v2_runner_on_unreachable(self, result): def v2_runner_on_unreachable(self, result):
if result._task.delegate_to: delegated_vars = result._result.get('_ansible_delegated_vars', None)
self._display.display("fatal: [%s -> %s]: UNREACHABLE! => %s" % (result._host.get_name(), result._task.delegate_to, self._dump_results(result._result)), color='red') if delegated_vars:
self._display.display("fatal: [%s -> %s]: UNREACHABLE! => %s" % (result._host.get_name(), delegated_vars['ansible_host'], self._dump_results(result._result)), color='red')
else: else:
self._display.display("fatal: [%s]: UNREACHABLE! => %s" % (result._host.get_name(), self._dump_results(result._result)), color='red') self._display.display("fatal: [%s]: UNREACHABLE! => %s" % (result._host.get_name(), self._dump_results(result._result)), color='red')
@ -126,23 +128,30 @@ class CallbackModule(CallbackBase):
def v2_playbook_item_on_ok(self, result): def v2_playbook_item_on_ok(self, result):
delegated_vars = result._result.get('_ansible_delegated_vars', None)
if result._task.action == 'include': if result._task.action == 'include':
msg = 'included: %s for %s' % (result._task.args.get('_raw_params'), result._host.name) return
color = 'cyan'
elif result._result.get('changed', False): elif result._result.get('changed', False):
if delegated_vars:
msg = "changed: [%s -> %s]" % (result._host.get_name(), delegated_vars['ansible_host'])
else:
msg = "changed: [%s]" % result._host.get_name() msg = "changed: [%s]" % result._host.get_name()
color = 'yellow' color = 'yellow'
else:
if delegated_vars:
msg = "ok: [%s -> %s]" % (result._host.get_name(), delegated_vars['ansible_host'])
else: else:
msg = "ok: [%s]" % result._host.get_name() msg = "ok: [%s]" % result._host.get_name()
color = 'green' color = 'green'
msg += " => (item=%s)" % (result._result['item'],) msg += " => (item=%s)" % (result._result['item'],)
if (self._display.verbosity > 0 or '_ansible_verbose_always' in result._result) and not '_ansible_verbose_override' in result._result and result._task.action != 'include': if (self._display.verbosity > 0 or '_ansible_verbose_always' in result._result) and not '_ansible_verbose_override' in result._result:
msg += " => %s" % self._dump_results(result._result) msg += " => %s" % self._dump_results(result._result)
self._display.display(msg, color=color) self._display.display(msg, color=color)
def v2_playbook_item_on_failed(self, result): def v2_playbook_item_on_failed(self, result):
delegated_vars = result._result.get('_ansible_delegated_vars', None)
if 'exception' in result._result: if 'exception' in result._result:
if self._display.verbosity < 3: if self._display.verbosity < 3:
# extract just the actual error message from the exception text # extract just the actual error message from the exception text
@ -156,6 +165,15 @@ class CallbackModule(CallbackBase):
# finally, remove the exception from the result so it's not shown every time # finally, remove the exception from the result so it's not shown every time
del result._result['exception'] del result._result['exception']
if delegated_vars:
self._display.display("failed: [%s -> %s] => (item=%s) => %s" % (result._host.get_name(), delegated_vars['ansible_host'], result._result['item'], self._dump_results(result._result)), color='red')
else:
self._display.display("failed: [%s] => (item=%s) => %s" % (result._host.get_name(), result._result['item'], self._dump_results(result._result)), color='red') self._display.display("failed: [%s] => (item=%s) => %s" % (result._host.get_name(), result._result['item'], self._dump_results(result._result)), color='red')
self._handle_warnings(result._result) self._handle_warnings(result._result)
def v2_playbook_on_include(self, included_file):
msg = 'included: %s for %s' % (included_file._filename, ", ".join([h.name for h in included_file._hosts]))
color = 'cyan'
self._display.display(msg, color='cyan')