added verbose option to show callback loaded info

also made mail module print nicer without all those 'u'
This commit is contained in:
Brian Coca 2015-07-10 23:48:12 -04:00
parent 4b9a79d42b
commit 7a1bce1b5d
10 changed files with 22 additions and 5 deletions

View file

@ -16,7 +16,7 @@
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
# Make coding more python3-ish
from __future__ import (absolute_import, division, print_function)
from __future__ import (absolute_import, division)
__metaclass__ = type
__all__ = ["CallbackBase"]
@ -34,6 +34,11 @@ class CallbackBase:
def __init__(self, display):
self._display = display
if self._display.verbosity >= 4:
name = getattr(self, 'CALLBACK_NAME', 'with no defined name')
ctype = getattr(self, 'CALLBACK_TYPE', 'unknwon')
version = getattr(self, 'CALLBACK_VERSION', 'unknwon')
self._display.vvvv('Loaded callback %s of type %s, v%s' % (name, ctype, version))
def set_connection_info(self, conn_info):
pass

View file

@ -24,6 +24,7 @@ class CallbackModule(CallbackBase):
"""
CALLBACK_VERSION = 2.0
CALLBACK_TYPE = 'aggregate'
CALLBACK_TYPE = 'context_demo'
def v2_on_any(self, *args, **kwargs):
i = 0

View file

@ -32,6 +32,7 @@ class CallbackModule(CallbackBase):
CALLBACK_VERSION = 2.0
CALLBACK_TYPE = 'stdout'
CALLBACK_NAME = 'default'
def v2_runner_on_failed(self, result, ignore_errors=False):
if 'exception' in result._result:

View file

@ -42,7 +42,8 @@ class CallbackModule(CallbackBase):
"""
CALLBACK_VERSION = 2.0
CALLBACK_TYPE = 'notification'
CALLBACK_VERSION = 2.0
CALLBACK_NAME = 'hipchat'
def __init__(self, display):

View file

@ -34,6 +34,7 @@ class CallbackModule(CallbackBase):
"""
CALLBACK_VERSION = 2.0
CALLBACK_TYPE = 'notification'
CALLBACK_NAME = 'log_plays'
TIME_FORMAT="%b %d %Y %H:%M:%S"
MSG_FORMAT="%(now)s - %(category)s - %(data)s\n\n"

View file

@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
# Copyright 2012 Dag Wieers <dag@wieers.com>
#
# This file is part of Ansible
@ -17,6 +18,7 @@
import os
import smtplib
import json
from ansible.plugins.callback import CallbackBase
def mail(subject='Ansible error mail', sender=None, to=None, cc=None, bcc=None, body=None, smtphost=None):
@ -58,6 +60,7 @@ class CallbackModule(CallbackBase):
"""
CALLBACK_VERSION = 2.0
CALLBACK_TYPE = 'notification'
CALLBACK_NAME = 'mail'
def v2_runner_on_failed(self, res, ignore_errors=False):
@ -66,8 +69,9 @@ class CallbackModule(CallbackBase):
if ignore_errors:
return
sender = '"Ansible: %s" <root>' % host
subject = 'Failed: %s' % (res._task.action)
body = 'The following task failed for host ' + host + ':\n\n%s\n\n' % (res._task.action)
attach = "%s: %s" % (res._result['invocation']['module_name'], json.dumps(res._result['invocation']['module_args']))
subject = 'Failed: %s' % attach
body = 'The following task failed for host ' + host + ':\n\n%s\n\n' % attach
if 'stdout' in res._result.keys() and res._result['stdout']:
subject = res._result['stdout'].strip('\r\n').split('\n')[-1]
@ -78,7 +82,7 @@ class CallbackModule(CallbackBase):
if 'msg' in res._result.keys() and res._result['msg']:
subject = res._result['msg'].strip('\r\n').split('\n')[0]
body += 'with the following message:\n\n' + res._result['msg'] + '\n\n'
body += 'A complete dump of the error:\n\n' + str(res._result['msg'])
body += 'A complete dump of the error:\n\n' + json.dumps(res._result, indent=4)
mail(sender=sender, subject=subject, body=body)
def v2_runner_on_unreachable(self, result):

View file

@ -33,6 +33,7 @@ class CallbackModule(CallbackBase):
CALLBACK_VERSION = 2.0
CALLBACK_TYPE = 'stdout'
CALLBACK_NAME = 'minimal'
def v2_on_any(self, *args, **kwargs):
pass

View file

@ -33,6 +33,7 @@ class CallbackModule(CallbackBase):
"""
CALLBACK_VERSION = 2.0
CALLBACK_TYPE = 'notification'
CALLBACK_NAME = 'osx_say'
def __init__(self, display):

View file

@ -21,6 +21,7 @@ class CallbackModule(CallbackBase):
"""
CALLBACK_VERSION = 2.0
CALLBACK_TYPE = 'aggregate'
CALLBACK_NAME = 'syslog_json'
def __init__(self, display):

View file

@ -10,6 +10,7 @@ class CallbackModule(CallbackBase):
"""
CALLBACK_VERSION = 2.0
CALLBACK_TYPE = 'aggregate'
CALLBACK_NAME = 'timer'
start_time = datetime.now()