added verbose option to show callback loaded info
also made mail module print nicer without all those 'u'
This commit is contained in:
parent
4b9a79d42b
commit
7a1bce1b5d
10 changed files with 22 additions and 5 deletions
|
@ -16,7 +16,7 @@
|
||||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
# Make coding more python3-ish
|
# Make coding more python3-ish
|
||||||
from __future__ import (absolute_import, division, print_function)
|
from __future__ import (absolute_import, division)
|
||||||
__metaclass__ = type
|
__metaclass__ = type
|
||||||
|
|
||||||
__all__ = ["CallbackBase"]
|
__all__ = ["CallbackBase"]
|
||||||
|
@ -34,6 +34,11 @@ class CallbackBase:
|
||||||
|
|
||||||
def __init__(self, display):
|
def __init__(self, display):
|
||||||
self._display = 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):
|
def set_connection_info(self, conn_info):
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -24,6 +24,7 @@ class CallbackModule(CallbackBase):
|
||||||
"""
|
"""
|
||||||
CALLBACK_VERSION = 2.0
|
CALLBACK_VERSION = 2.0
|
||||||
CALLBACK_TYPE = 'aggregate'
|
CALLBACK_TYPE = 'aggregate'
|
||||||
|
CALLBACK_TYPE = 'context_demo'
|
||||||
|
|
||||||
def v2_on_any(self, *args, **kwargs):
|
def v2_on_any(self, *args, **kwargs):
|
||||||
i = 0
|
i = 0
|
||||||
|
|
|
@ -32,6 +32,7 @@ class CallbackModule(CallbackBase):
|
||||||
|
|
||||||
CALLBACK_VERSION = 2.0
|
CALLBACK_VERSION = 2.0
|
||||||
CALLBACK_TYPE = 'stdout'
|
CALLBACK_TYPE = 'stdout'
|
||||||
|
CALLBACK_NAME = 'default'
|
||||||
|
|
||||||
def v2_runner_on_failed(self, result, ignore_errors=False):
|
def v2_runner_on_failed(self, result, ignore_errors=False):
|
||||||
if 'exception' in result._result:
|
if 'exception' in result._result:
|
||||||
|
|
|
@ -42,7 +42,8 @@ class CallbackModule(CallbackBase):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
CALLBACK_VERSION = 2.0
|
CALLBACK_VERSION = 2.0
|
||||||
CALLBACK_TYPE = 'notification'
|
CALLBACK_VERSION = 2.0
|
||||||
|
CALLBACK_NAME = 'hipchat'
|
||||||
|
|
||||||
def __init__(self, display):
|
def __init__(self, display):
|
||||||
|
|
||||||
|
|
|
@ -34,6 +34,7 @@ class CallbackModule(CallbackBase):
|
||||||
"""
|
"""
|
||||||
CALLBACK_VERSION = 2.0
|
CALLBACK_VERSION = 2.0
|
||||||
CALLBACK_TYPE = 'notification'
|
CALLBACK_TYPE = 'notification'
|
||||||
|
CALLBACK_NAME = 'log_plays'
|
||||||
|
|
||||||
TIME_FORMAT="%b %d %Y %H:%M:%S"
|
TIME_FORMAT="%b %d %Y %H:%M:%S"
|
||||||
MSG_FORMAT="%(now)s - %(category)s - %(data)s\n\n"
|
MSG_FORMAT="%(now)s - %(category)s - %(data)s\n\n"
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
# Copyright 2012 Dag Wieers <dag@wieers.com>
|
# Copyright 2012 Dag Wieers <dag@wieers.com>
|
||||||
#
|
#
|
||||||
# This file is part of Ansible
|
# This file is part of Ansible
|
||||||
|
@ -17,6 +18,7 @@
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import smtplib
|
import smtplib
|
||||||
|
import json
|
||||||
from ansible.plugins.callback import CallbackBase
|
from ansible.plugins.callback import CallbackBase
|
||||||
|
|
||||||
def mail(subject='Ansible error mail', sender=None, to=None, cc=None, bcc=None, body=None, smtphost=None):
|
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_VERSION = 2.0
|
||||||
CALLBACK_TYPE = 'notification'
|
CALLBACK_TYPE = 'notification'
|
||||||
|
CALLBACK_NAME = 'mail'
|
||||||
|
|
||||||
def v2_runner_on_failed(self, res, ignore_errors=False):
|
def v2_runner_on_failed(self, res, ignore_errors=False):
|
||||||
|
|
||||||
|
@ -66,8 +69,9 @@ class CallbackModule(CallbackBase):
|
||||||
if ignore_errors:
|
if ignore_errors:
|
||||||
return
|
return
|
||||||
sender = '"Ansible: %s" <root>' % host
|
sender = '"Ansible: %s" <root>' % host
|
||||||
subject = 'Failed: %s' % (res._task.action)
|
attach = "%s: %s" % (res._result['invocation']['module_name'], json.dumps(res._result['invocation']['module_args']))
|
||||||
body = 'The following task failed for host ' + host + ':\n\n%s\n\n' % (res._task.action)
|
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']:
|
if 'stdout' in res._result.keys() and res._result['stdout']:
|
||||||
subject = res._result['stdout'].strip('\r\n').split('\n')[-1]
|
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']:
|
if 'msg' in res._result.keys() and res._result['msg']:
|
||||||
subject = res._result['msg'].strip('\r\n').split('\n')[0]
|
subject = res._result['msg'].strip('\r\n').split('\n')[0]
|
||||||
body += 'with the following message:\n\n' + res._result['msg'] + '\n\n'
|
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)
|
mail(sender=sender, subject=subject, body=body)
|
||||||
|
|
||||||
def v2_runner_on_unreachable(self, result):
|
def v2_runner_on_unreachable(self, result):
|
||||||
|
|
|
@ -33,6 +33,7 @@ class CallbackModule(CallbackBase):
|
||||||
|
|
||||||
CALLBACK_VERSION = 2.0
|
CALLBACK_VERSION = 2.0
|
||||||
CALLBACK_TYPE = 'stdout'
|
CALLBACK_TYPE = 'stdout'
|
||||||
|
CALLBACK_NAME = 'minimal'
|
||||||
|
|
||||||
def v2_on_any(self, *args, **kwargs):
|
def v2_on_any(self, *args, **kwargs):
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -33,6 +33,7 @@ class CallbackModule(CallbackBase):
|
||||||
"""
|
"""
|
||||||
CALLBACK_VERSION = 2.0
|
CALLBACK_VERSION = 2.0
|
||||||
CALLBACK_TYPE = 'notification'
|
CALLBACK_TYPE = 'notification'
|
||||||
|
CALLBACK_NAME = 'osx_say'
|
||||||
|
|
||||||
def __init__(self, display):
|
def __init__(self, display):
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@ class CallbackModule(CallbackBase):
|
||||||
"""
|
"""
|
||||||
CALLBACK_VERSION = 2.0
|
CALLBACK_VERSION = 2.0
|
||||||
CALLBACK_TYPE = 'aggregate'
|
CALLBACK_TYPE = 'aggregate'
|
||||||
|
CALLBACK_NAME = 'syslog_json'
|
||||||
|
|
||||||
def __init__(self, display):
|
def __init__(self, display):
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@ class CallbackModule(CallbackBase):
|
||||||
"""
|
"""
|
||||||
CALLBACK_VERSION = 2.0
|
CALLBACK_VERSION = 2.0
|
||||||
CALLBACK_TYPE = 'aggregate'
|
CALLBACK_TYPE = 'aggregate'
|
||||||
|
CALLBACK_NAME = 'timer'
|
||||||
|
|
||||||
start_time = datetime.now()
|
start_time = datetime.now()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue