2014-11-14 22:14:08 +00:00
|
|
|
# (c) 2012-2014, Michael DeHaan <michael.dehaan@gmail.com>
|
2017-08-20 15:20:30 +00:00
|
|
|
# (c) 2017 Ansible Project
|
|
|
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
|
|
|
|
2017-09-08 18:08:31 +00:00
|
|
|
# Make coding more python3-ish
|
|
|
|
from __future__ import (absolute_import, division, print_function)
|
|
|
|
__metaclass__ = type
|
|
|
|
|
|
|
|
DOCUMENTATION = '''
|
2017-08-20 15:20:30 +00:00
|
|
|
callback: minimal
|
|
|
|
type: stdout
|
|
|
|
short_description: minimal Ansible screen output
|
|
|
|
version_added: historical
|
|
|
|
description:
|
|
|
|
- This is the default output callback used by the ansible command (ad-hoc)
|
|
|
|
'''
|
2014-11-14 22:14:08 +00:00
|
|
|
|
|
|
|
from ansible.plugins.callback import CallbackBase
|
2015-07-23 17:42:20 +00:00
|
|
|
from ansible import constants as C
|
2014-11-14 22:14:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
class CallbackModule(CallbackBase):
|
|
|
|
|
|
|
|
'''
|
|
|
|
This is the default callback interface, which simply prints messages
|
|
|
|
to stdout when new callback events are received.
|
|
|
|
'''
|
|
|
|
|
2015-03-25 18:51:40 +00:00
|
|
|
CALLBACK_VERSION = 2.0
|
2015-04-29 06:06:33 +00:00
|
|
|
CALLBACK_TYPE = 'stdout'
|
2015-07-11 03:48:12 +00:00
|
|
|
CALLBACK_NAME = 'minimal'
|
2015-03-25 18:51:40 +00:00
|
|
|
|
2015-10-23 18:08:55 +00:00
|
|
|
def _command_generic_msg(self, host, result, caption):
|
2015-07-23 17:42:20 +00:00
|
|
|
''' output the result of a command run '''
|
|
|
|
|
2016-12-07 16:00:11 +00:00
|
|
|
buf = "%s | %s | rc=%s >>\n" % (host, caption, result.get('rc', -1))
|
2017-06-02 11:14:11 +00:00
|
|
|
buf += result.get('stdout', '')
|
|
|
|
buf += result.get('stderr', '')
|
|
|
|
buf += result.get('msg', '')
|
2015-07-23 17:42:20 +00:00
|
|
|
|
|
|
|
return buf + "\n"
|
|
|
|
|
2015-04-15 02:10:56 +00:00
|
|
|
def v2_runner_on_failed(self, result, ignore_errors=False):
|
2015-06-23 16:12:21 +00:00
|
|
|
|
2017-02-27 18:29:40 +00:00
|
|
|
self._handle_exception(result._result)
|
2017-02-08 15:58:39 +00:00
|
|
|
self._handle_warnings(result._result)
|
|
|
|
|
2016-12-07 16:00:11 +00:00
|
|
|
if result._task.action in C.MODULE_NO_JSON and 'module_stderr' not in result._result:
|
2015-12-29 20:41:00 +00:00
|
|
|
self._display.display(self._command_generic_msg(result._host.get_name(), result._result, "FAILED"), color=C.COLOR_ERROR)
|
2015-07-23 17:42:20 +00:00
|
|
|
else:
|
2015-12-29 20:41:00 +00:00
|
|
|
self._display.display("%s | FAILED! => %s" % (result._host.get_name(), self._dump_results(result._result, indent=4)), color=C.COLOR_ERROR)
|
2014-11-14 22:14:08 +00:00
|
|
|
|
2015-04-15 02:10:56 +00:00
|
|
|
def v2_runner_on_ok(self, result):
|
2015-12-15 14:27:53 +00:00
|
|
|
self._clean_results(result._result, result._task.action)
|
2017-02-08 15:58:39 +00:00
|
|
|
|
|
|
|
self._handle_warnings(result._result)
|
|
|
|
|
2015-07-23 17:42:20 +00:00
|
|
|
if result._task.action in C.MODULE_NO_JSON:
|
2015-12-29 20:41:00 +00:00
|
|
|
self._display.display(self._command_generic_msg(result._host.get_name(), result._result, "SUCCESS"), color=C.COLOR_OK)
|
2015-07-23 17:42:20 +00:00
|
|
|
else:
|
2015-12-29 20:41:00 +00:00
|
|
|
if 'changed' in result._result and result._result['changed']:
|
|
|
|
self._display.display("%s | SUCCESS => %s" % (result._host.get_name(), self._dump_results(result._result, indent=4)), color=C.COLOR_CHANGED)
|
|
|
|
else:
|
|
|
|
self._display.display("%s | SUCCESS => %s" % (result._host.get_name(), self._dump_results(result._result, indent=4)), color=C.COLOR_OK)
|
2014-11-14 22:14:08 +00:00
|
|
|
|
2015-04-15 02:10:56 +00:00
|
|
|
def v2_runner_on_skipped(self, result):
|
2015-12-29 20:41:00 +00:00
|
|
|
self._display.display("%s | SKIPPED" % (result._host.get_name()), color=C.COLOR_SKIP)
|
2014-11-14 22:14:08 +00:00
|
|
|
|
2015-04-15 02:10:56 +00:00
|
|
|
def v2_runner_on_unreachable(self, result):
|
2015-12-29 20:41:00 +00:00
|
|
|
self._display.display("%s | UNREACHABLE! => %s" % (result._host.get_name(), self._dump_results(result._result, indent=4)), color=C.COLOR_UNREACHABLE)
|
2015-07-27 02:29:56 +00:00
|
|
|
|
|
|
|
def v2_on_file_diff(self, result):
|
2015-08-16 06:19:43 +00:00
|
|
|
if 'diff' in result._result and result._result['diff']:
|
2015-07-27 02:29:56 +00:00
|
|
|
self._display.display(self._get_diff(result._result['diff']))
|