mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-02 06:30:19 -07:00
parent
2f33c1a1a1
commit
5553b20828
206 changed files with 1853 additions and 1870 deletions
|
@ -213,7 +213,6 @@ class CallbackBase:
|
|||
if remove_key in result:
|
||||
del result[remove_key]
|
||||
|
||||
|
||||
def set_play_context(self, play_context):
|
||||
pass
|
||||
|
||||
|
@ -280,7 +279,7 @@ class CallbackBase:
|
|||
def on_file_diff(self, host, diff):
|
||||
pass
|
||||
|
||||
####### V2 METHODS, by default they call v1 counterparts if possible ######
|
||||
# V2 METHODS, by default they call v1 counterparts if possible
|
||||
def v2_on_any(self, *args, **kwargs):
|
||||
self.on_any(args, kwargs)
|
||||
|
||||
|
@ -295,7 +294,7 @@ class CallbackBase:
|
|||
def v2_runner_on_skipped(self, result):
|
||||
if C.DISPLAY_SKIPPED_HOSTS:
|
||||
host = result._host.get_name()
|
||||
self.runner_on_skipped(host, self._get_item(getattr(result._result,'results',{})))
|
||||
self.runner_on_skipped(host, self._get_item(getattr(result._result, 'results', {})))
|
||||
|
||||
def v2_runner_on_unreachable(self, result):
|
||||
host = result._host.get_name()
|
||||
|
@ -307,7 +306,7 @@ class CallbackBase:
|
|||
def v2_runner_on_async_poll(self, result):
|
||||
host = result._host.get_name()
|
||||
jid = result._result.get('ansible_job_id')
|
||||
#FIXME, get real clock
|
||||
# FIXME, get real clock
|
||||
clock = 0
|
||||
self.runner_on_async_poll(host, result._result, jid, clock)
|
||||
|
||||
|
@ -322,7 +321,7 @@ class CallbackBase:
|
|||
self.runner_on_async_failed(host, result._result, jid)
|
||||
|
||||
def v2_runner_on_file_diff(self, result, diff):
|
||||
pass #no v1 correspondance
|
||||
pass # no v1 correspondance
|
||||
|
||||
def v2_playbook_on_start(self, playbook):
|
||||
self.playbook_on_start()
|
||||
|
@ -341,10 +340,10 @@ class CallbackBase:
|
|||
self.playbook_on_task_start(task.name, is_conditional)
|
||||
|
||||
def v2_playbook_on_cleanup_task_start(self, task):
|
||||
pass #no v1 correspondance
|
||||
pass # no v1 correspondance
|
||||
|
||||
def v2_playbook_on_handler_task_start(self, task):
|
||||
pass #no v1 correspondance
|
||||
pass # no v1 correspondance
|
||||
|
||||
def v2_playbook_on_vars_prompt(self, varname, private=True, prompt=None, encrypt=None, confirm=False, salt_size=None, salt=None, default=None):
|
||||
self.playbook_on_vars_prompt(varname, private, prompt, encrypt, confirm, salt_size, salt, default)
|
||||
|
@ -372,7 +371,7 @@ class CallbackBase:
|
|||
self.on_file_diff(host, result._result['diff'])
|
||||
|
||||
def v2_playbook_on_include(self, included_file):
|
||||
pass #no v1 correspondance
|
||||
pass # no v1 correspondance
|
||||
|
||||
def v2_runner_item_on_ok(self, result):
|
||||
pass
|
||||
|
|
|
@ -21,6 +21,7 @@ __metaclass__ = type
|
|||
|
||||
from ansible.plugins.callback.default import CallbackModule as CallbackModule_default
|
||||
|
||||
|
||||
class CallbackModule(CallbackModule_default):
|
||||
|
||||
CALLBACK_VERSION = 2.0
|
||||
|
@ -76,4 +77,3 @@ class CallbackModule(CallbackModule_default):
|
|||
def v2_runner_item_on_failed(self, result):
|
||||
self.display_task_banner()
|
||||
self.super_ref.v2_runner_item_on_failed(result)
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@ __metaclass__ = type
|
|||
|
||||
from ansible.plugins.callback import CallbackBase
|
||||
|
||||
|
||||
class CallbackModule(CallbackBase):
|
||||
"""
|
||||
This is a very trivial example of how any callback function can get at play and task objects.
|
||||
|
|
|
@ -30,6 +30,7 @@ from ansible import constants as C
|
|||
from ansible.plugins.callback import CallbackBase
|
||||
from ansible.utils.color import colorize, hostcolor
|
||||
|
||||
|
||||
class CallbackModule(CallbackBase):
|
||||
|
||||
'''
|
||||
|
@ -100,7 +101,7 @@ class CallbackModule(CallbackBase):
|
|||
self._process_items(result)
|
||||
else:
|
||||
|
||||
if (self._display.verbosity > 0 or '_ansible_verbose_always' in result._result) and not '_ansible_verbose_override' in result._result:
|
||||
if (self._display.verbosity > 0 or '_ansible_verbose_always' in result._result) and '_ansible_verbose_override' not in result._result:
|
||||
msg += " => %s" % (self._dump_results(result._result),)
|
||||
self._display.display(msg, color=color)
|
||||
|
||||
|
@ -113,7 +114,7 @@ class CallbackModule(CallbackBase):
|
|||
self._process_items(result)
|
||||
else:
|
||||
msg = "skipping: [%s]" % result._host.get_name()
|
||||
if (self._display.verbosity > 0 or '_ansible_verbose_always' in result._result) and not '_ansible_verbose_override' in result._result:
|
||||
if (self._display.verbosity > 0 or '_ansible_verbose_always' in result._result) and '_ansible_verbose_override' not in result._result:
|
||||
msg += " => %s" % self._dump_results(result._result)
|
||||
self._display.display(msg, color=C.COLOR_SKIP)
|
||||
|
||||
|
@ -209,7 +210,7 @@ class CallbackModule(CallbackBase):
|
|||
|
||||
msg += " => (item=%s)" % (self._get_item(result._result),)
|
||||
|
||||
if (self._display.verbosity > 0 or '_ansible_verbose_always' in result._result) and not '_ansible_verbose_override' in result._result:
|
||||
if (self._display.verbosity > 0 or '_ansible_verbose_always' in result._result) and '_ansible_verbose_override' not in result._result:
|
||||
msg += " => %s" % self._dump_results(result._result)
|
||||
self._display.display(msg, color=color)
|
||||
|
||||
|
@ -230,7 +231,7 @@ class CallbackModule(CallbackBase):
|
|||
def v2_runner_item_on_skipped(self, result):
|
||||
if C.DISPLAY_SKIPPED_HOSTS:
|
||||
msg = "skipping: [%s] => (item=%s) " % (result._host.get_name(), self._get_item(result._result))
|
||||
if (self._display.verbosity > 0 or '_ansible_verbose_always' in result._result) and not '_ansible_verbose_override' in result._result:
|
||||
if (self._display.verbosity > 0 or '_ansible_verbose_always' in result._result) and '_ansible_verbose_override' not in result._result:
|
||||
msg += " => %s" % self._dump_results(result._result)
|
||||
self._display.display(msg, color=C.COLOR_SKIP)
|
||||
|
||||
|
@ -269,16 +270,16 @@ class CallbackModule(CallbackBase):
|
|||
if C.SHOW_CUSTOM_STATS and stats.custom:
|
||||
self._display.banner("CUSTOM STATS: ")
|
||||
# per host
|
||||
#TODO: come up with 'pretty format'
|
||||
# TODO: come up with 'pretty format'
|
||||
for k in sorted(stats.custom.keys()):
|
||||
if k == '_run':
|
||||
continue
|
||||
self._display.display('\t%s: %s' % (k, self._dump_results(stats.custom[k], indent=1).replace('\n','')))
|
||||
self._display.display('\t%s: %s' % (k, self._dump_results(stats.custom[k], indent=1).replace('\n', '')))
|
||||
|
||||
# print per run custom stats
|
||||
if '_run' in stats.custom:
|
||||
self._display.display("", screen_only=True)
|
||||
self._display.display('\tRUN: %s' % self._dump_results(stats.custom['_run'], indent=1).replace('\n',''))
|
||||
self._display.display('\tRUN: %s' % self._dump_results(stats.custom['_run'], indent=1).replace('\n', ''))
|
||||
self._display.display("", screen_only=True)
|
||||
|
||||
def v2_playbook_on_start(self, playbook):
|
||||
|
@ -291,13 +292,13 @@ class CallbackModule(CallbackBase):
|
|||
for option in dir(self._options):
|
||||
if option.startswith('_') or option in ['read_file', 'ensure_value', 'read_module']:
|
||||
continue
|
||||
val = getattr(self._options,option)
|
||||
val = getattr(self._options, option)
|
||||
if val:
|
||||
self._display.vvvv('%s: %s' % (option,val))
|
||||
self._display.vvvv('%s: %s' % (option, val))
|
||||
|
||||
def v2_runner_retry(self, result):
|
||||
task_name = result.task_name or result._task
|
||||
msg = "FAILED - RETRYING: %s (%d retries left)." % (task_name, result._result['retries'] - result._result['attempts'])
|
||||
if (self._display.verbosity > 2 or '_ansible_verbose_always' in result._result) and not '_ansible_verbose_override' in result._result:
|
||||
if (self._display.verbosity > 2 or '_ansible_verbose_always' in result._result) and '_ansible_verbose_override' not in result._result:
|
||||
msg += "Result was: %s" % self._dump_results(result._result)
|
||||
self._display.display(msg, color=C.COLOR_DEBUG)
|
||||
|
|
|
@ -71,18 +71,18 @@ import sys
|
|||
|
||||
|
||||
# FIXME: Importing constants as C simply does not work, beats me :-/
|
||||
#from ansible import constants as C
|
||||
# from ansible import constants as C
|
||||
class C:
|
||||
COLOR_HIGHLIGHT = 'white'
|
||||
COLOR_VERBOSE = 'blue'
|
||||
COLOR_WARN = 'bright purple'
|
||||
COLOR_ERROR = 'red'
|
||||
COLOR_DEBUG = 'dark gray'
|
||||
COLOR_DEPRECATE = 'purple'
|
||||
COLOR_SKIP = 'cyan'
|
||||
COLOR_HIGHLIGHT = 'white'
|
||||
COLOR_VERBOSE = 'blue'
|
||||
COLOR_WARN = 'bright purple'
|
||||
COLOR_ERROR = 'red'
|
||||
COLOR_DEBUG = 'dark gray'
|
||||
COLOR_DEPRECATE = 'purple'
|
||||
COLOR_SKIP = 'cyan'
|
||||
COLOR_UNREACHABLE = 'bright red'
|
||||
COLOR_OK = 'green'
|
||||
COLOR_CHANGED = 'yellow'
|
||||
COLOR_OK = 'green'
|
||||
COLOR_CHANGED = 'yellow'
|
||||
|
||||
|
||||
# Taken from Dstat
|
||||
|
@ -136,15 +136,16 @@ class vt100:
|
|||
|
||||
|
||||
colors = dict(
|
||||
ok = vt100.darkgreen,
|
||||
changed = vt100.darkyellow,
|
||||
skipped = vt100.darkcyan,
|
||||
ignored = vt100.cyanbg + vt100.red,
|
||||
failed = vt100.darkred,
|
||||
unreachable = vt100.red,
|
||||
ok=vt100.darkgreen,
|
||||
changed=vt100.darkyellow,
|
||||
skipped=vt100.darkcyan,
|
||||
ignored=vt100.cyanbg + vt100.red,
|
||||
failed=vt100.darkred,
|
||||
unreachable=vt100.red,
|
||||
)
|
||||
|
||||
states = ( 'skipped', 'ok', 'changed', 'failed', 'unreachable' )
|
||||
states = ('skipped', 'ok', 'changed', 'failed', 'unreachable')
|
||||
|
||||
|
||||
class CallbackModule_dense(CallbackModule_default):
|
||||
|
||||
|
@ -156,7 +157,6 @@ class CallbackModule_dense(CallbackModule_default):
|
|||
CALLBACK_TYPE = 'stdout'
|
||||
CALLBACK_NAME = 'dense'
|
||||
|
||||
|
||||
def __init__(self):
|
||||
|
||||
# From CallbackModule
|
||||
|
|
|
@ -123,11 +123,17 @@ class CallbackModule(CallbackBase):
|
|||
level = 'err'
|
||||
else:
|
||||
level = 'notice' if 'changed' in msg and msg['changed'] else 'info'
|
||||
logs.append({"log": {
|
||||
'sources': {'source': source},
|
||||
'messages': {'message': json.dumps(msg)},
|
||||
'level': level
|
||||
}})
|
||||
logs.append({
|
||||
"log": {
|
||||
'sources': {
|
||||
'source': source
|
||||
},
|
||||
'messages': {
|
||||
'message': json.dumps(msg)
|
||||
},
|
||||
'level': level
|
||||
}
|
||||
})
|
||||
return logs
|
||||
|
||||
def send_reports(self, stats):
|
||||
|
@ -154,8 +160,8 @@ class CallbackModule(CallbackBase):
|
|||
"metrics": metrics,
|
||||
"status": status,
|
||||
"logs": log,
|
||||
}
|
||||
}
|
||||
}
|
||||
# To be changed to /api/v2/config_reports in 1.11. Maybe we
|
||||
# could make a GET request to get the Foreman version & do
|
||||
# this automatically.
|
||||
|
|
|
@ -58,7 +58,7 @@ class CallbackModule(CallbackBase):
|
|||
if not HAS_PRETTYTABLE:
|
||||
self.disabled = True
|
||||
self._display.warning('The `prettytable` python module is not installed. '
|
||||
'Disabling the HipChat callback plugin.')
|
||||
'Disabling the HipChat callback plugin.')
|
||||
|
||||
self.msg_uri = 'https://api.hipchat.com/v1/rooms/message'
|
||||
self.token = os.getenv('HIPCHAT_TOKEN')
|
||||
|
@ -69,8 +69,8 @@ class CallbackModule(CallbackBase):
|
|||
if self.token is None:
|
||||
self.disabled = True
|
||||
self._display.warning('HipChat token could not be loaded. The HipChat '
|
||||
'token can be provided using the `HIPCHAT_TOKEN` '
|
||||
'environment variable.')
|
||||
'token can be provided using the `HIPCHAT_TOKEN` '
|
||||
'environment variable.')
|
||||
|
||||
self.printed_playbook = False
|
||||
self.playbook_name = None
|
||||
|
|
|
@ -39,8 +39,8 @@ class CallbackModule(CallbackBase):
|
|||
super(CallbackModule, self).__init__(display=display)
|
||||
|
||||
if not HAS_XMPP:
|
||||
self._display.warning("The required python xmpp library (xmpppy) is not installed."
|
||||
" pip install git+https://github.com/ArchipelProject/xmpppy")
|
||||
self._display.warning("The required python xmpp library (xmpppy) is not installed. "
|
||||
"pip install git+https://github.com/ArchipelProject/xmpppy")
|
||||
self.disabled = True
|
||||
|
||||
self.serv = os.getenv('JABBER_SERV')
|
||||
|
@ -48,15 +48,15 @@ class CallbackModule(CallbackBase):
|
|||
self.j_pass = os.getenv('JABBER_PASS')
|
||||
self.j_to = os.getenv('JABBER_TO')
|
||||
|
||||
if (self.j_user or self.j_pass or self.serv ) is None:
|
||||
if (self.j_user or self.j_pass or self.serv) is None:
|
||||
self.disabled = True
|
||||
self._display.warning ('Jabber CallBack want JABBER_USER and JABBER_PASS env variables')
|
||||
self._display.warning('Jabber CallBack want JABBER_USER and JABBER_PASS env variables')
|
||||
|
||||
def send_msg(self, msg):
|
||||
"""Send message"""
|
||||
jid = xmpp.JID(self.j_user)
|
||||
client = xmpp.Client(self.serv,debug=[])
|
||||
client.connect(server=(self.serv,5222))
|
||||
client = xmpp.Client(self.serv, debug=[])
|
||||
client.connect(server=(self.serv, 5222))
|
||||
client.auth(jid.getNode(), self.j_pass, resource=jid.getResource())
|
||||
message = xmpp.Message(self.j_to, msg)
|
||||
message.setAttr('type', 'chat')
|
||||
|
@ -93,5 +93,4 @@ class CallbackModule(CallbackBase):
|
|||
self.send_msg("%s: Failures detected \n%s \nHost: %s\n Failed at:\n%s" % (name, self.task, h, out))
|
||||
else:
|
||||
out = self.debug
|
||||
self.send_msg("Great! \n Playbook %s completed:\n%s \n Last task debug:\n %s" % (name,s, out))
|
||||
|
||||
self.send_msg("Great! \n Playbook %s completed:\n%s \n Last task debug:\n %s" % (name, s, out))
|
||||
|
|
|
@ -44,8 +44,8 @@ class CallbackModule(CallbackBase):
|
|||
CALLBACK_NAME = 'log_plays'
|
||||
CALLBACK_NEEDS_WHITELIST = True
|
||||
|
||||
TIME_FORMAT="%b %d %Y %H:%M:%S"
|
||||
MSG_FORMAT="%(now)s - %(category)s - %(data)s\n\n"
|
||||
TIME_FORMAT = "%b %d %Y %H:%M:%S"
|
||||
MSG_FORMAT = "%(now)s - %(category)s - %(data)s\n\n"
|
||||
|
||||
def __init__(self):
|
||||
|
||||
|
|
|
@ -160,10 +160,10 @@ class PlainTextSocketAppender(object):
|
|||
|
||||
try:
|
||||
import ssl
|
||||
HAS_SSL=True
|
||||
HAS_SSL = True
|
||||
except ImportError: # for systems without TLS support.
|
||||
SocketAppender = PlainTextSocketAppender
|
||||
HAS_SSL=False
|
||||
HAS_SSL = False
|
||||
else:
|
||||
|
||||
class TLSSocketAppender(PlainTextSocketAppender):
|
||||
|
@ -199,14 +199,14 @@ class CallbackModule(CallbackBase):
|
|||
self._display.warning("Unable to import ssl module. Will send over port 80.")
|
||||
|
||||
if not HAS_CERTIFI:
|
||||
self.disabled =True
|
||||
self.disabled = True
|
||||
self._display.warning('The `certifi` python module is not installed. '
|
||||
'Disabling the Logentries callback plugin.')
|
||||
'Disabling the Logentries callback plugin.')
|
||||
|
||||
if not HAS_FLATDICT:
|
||||
self.disabled =True
|
||||
self.disabled = True
|
||||
self._display.warning('The `flatdict` python module is not installed. '
|
||||
'Disabling the Logentries callback plugin.')
|
||||
'Disabling the Logentries callback plugin.')
|
||||
|
||||
config_path = os.path.abspath(os.path.dirname(__file__))
|
||||
config = configparser.ConfigParser()
|
||||
|
|
|
@ -33,6 +33,7 @@ except ImportError:
|
|||
|
||||
from ansible.plugins.callback import CallbackBase
|
||||
|
||||
|
||||
class CallbackModule(CallbackBase):
|
||||
"""
|
||||
ansible logstash callback plugin
|
||||
|
@ -69,9 +70,9 @@ class CallbackModule(CallbackBase):
|
|||
if not HAS_LOGSTASH:
|
||||
self.disabled = True
|
||||
self._display.warning("The required python-logstash is not installed. "
|
||||
"pip install python-logstash")
|
||||
"pip install python-logstash")
|
||||
else:
|
||||
self.logger = logging.getLogger('python-logstash-logger')
|
||||
self.logger = logging.getLogger('python-logstash-logger')
|
||||
self.logger.setLevel(logging.DEBUG)
|
||||
|
||||
self.handler = logstash.TCPLogstashHandler(
|
||||
|
@ -95,7 +96,7 @@ class CallbackModule(CallbackBase):
|
|||
'ansible_type': "start",
|
||||
'ansible_playbook': self.playbook,
|
||||
}
|
||||
self.logger.info("ansible start", extra = data)
|
||||
self.logger.info("ansible start", extra=data)
|
||||
|
||||
def v2_playbook_on_stats(self, stats):
|
||||
summarize_stat = {}
|
||||
|
@ -115,7 +116,7 @@ class CallbackModule(CallbackBase):
|
|||
'ansible_playbook': self.playbook,
|
||||
'ansible_result': json.dumps(summarize_stat),
|
||||
}
|
||||
self.logger.info("ansible stats", extra = data)
|
||||
self.logger.info("ansible stats", extra=data)
|
||||
|
||||
def v2_runner_on_ok(self, result, **kwargs):
|
||||
data = {
|
||||
|
@ -128,7 +129,7 @@ class CallbackModule(CallbackBase):
|
|||
'ansible_task': result._task,
|
||||
'ansible_result': self._dump_results(result._result)
|
||||
}
|
||||
self.logger.info("ansible ok", extra = data)
|
||||
self.logger.info("ansible ok", extra=data)
|
||||
|
||||
def v2_runner_on_skipped(self, result, **kwargs):
|
||||
data = {
|
||||
|
@ -140,7 +141,7 @@ class CallbackModule(CallbackBase):
|
|||
'ansible_task': result._task,
|
||||
'ansible_host': result._host.name
|
||||
}
|
||||
self.logger.info("ansible skipped", extra = data)
|
||||
self.logger.info("ansible skipped", extra=data)
|
||||
|
||||
def v2_playbook_on_import_for_host(self, result, imported_file):
|
||||
data = {
|
||||
|
@ -152,7 +153,7 @@ class CallbackModule(CallbackBase):
|
|||
'ansible_host': result._host.name,
|
||||
'imported_file': imported_file
|
||||
}
|
||||
self.logger.info("ansible import", extra = data)
|
||||
self.logger.info("ansible import", extra=data)
|
||||
|
||||
def v2_playbook_on_not_import_for_host(self, result, missing_file):
|
||||
data = {
|
||||
|
@ -164,7 +165,7 @@ class CallbackModule(CallbackBase):
|
|||
'ansible_host': result._host.name,
|
||||
'missing_file': missing_file
|
||||
}
|
||||
self.logger.info("ansible import", extra = data)
|
||||
self.logger.info("ansible import", extra=data)
|
||||
|
||||
def v2_runner_on_failed(self, result, **kwargs):
|
||||
data = {
|
||||
|
@ -178,7 +179,7 @@ class CallbackModule(CallbackBase):
|
|||
'ansible_result': self._dump_results(result._result)
|
||||
}
|
||||
self.errors += 1
|
||||
self.logger.error("ansible failed", extra = data)
|
||||
self.logger.error("ansible failed", extra=data)
|
||||
|
||||
def v2_runner_on_unreachable(self, result, **kwargs):
|
||||
data = {
|
||||
|
@ -191,7 +192,7 @@ class CallbackModule(CallbackBase):
|
|||
'ansible_task': result._task,
|
||||
'ansible_result': self._dump_results(result._result)
|
||||
}
|
||||
self.logger.error("ansbile unreachable", extra = data)
|
||||
self.logger.error("ansbile unreachable", extra=data)
|
||||
|
||||
def v2_runner_on_async_failed(self, result, **kwargs):
|
||||
data = {
|
||||
|
@ -205,4 +206,4 @@ class CallbackModule(CallbackBase):
|
|||
'ansible_result': self._dump_results(result._result)
|
||||
}
|
||||
self.errors += 1
|
||||
self.logger.error("ansible async", extra = data)
|
||||
self.logger.error("ansible async", extra=data)
|
||||
|
|
|
@ -32,11 +32,11 @@ from ansible.plugins.callback import CallbackBase
|
|||
def mail(subject='Ansible error mail', sender=None, to=None, cc=None, bcc=None, body=None, smtphost=None):
|
||||
|
||||
if sender is None:
|
||||
sender='<root>'
|
||||
sender = '<root>'
|
||||
if to is None:
|
||||
to='root'
|
||||
to = 'root'
|
||||
if smtphost is None:
|
||||
smtphost=os.getenv('SMTPHOST', 'localhost')
|
||||
smtphost = os.getenv('SMTPHOST', 'localhost')
|
||||
|
||||
if body is None:
|
||||
body = subject
|
||||
|
|
|
@ -38,9 +38,9 @@ class CallbackModule(CallbackBase):
|
|||
''' output the result of a command run '''
|
||||
|
||||
buf = "%s | %s | rc=%s >>\n" % (host, caption, result.get('rc', -1))
|
||||
buf += result.get('stdout','')
|
||||
buf += result.get('stderr','')
|
||||
buf += result.get('msg','')
|
||||
buf += result.get('stdout', '')
|
||||
buf += result.get('stderr', '')
|
||||
buf += result.get('msg', '')
|
||||
|
||||
return buf + "\n"
|
||||
|
||||
|
|
|
@ -34,10 +34,10 @@ class CallbackModule(CallbackBase):
|
|||
CALLBACK_TYPE = 'stdout'
|
||||
CALLBACK_NAME = 'oneline'
|
||||
|
||||
def _command_generic_msg(self, hostname, result, caption):
|
||||
stdout = result.get('stdout','').replace('\n', '\\n').replace('\r', '\\r')
|
||||
def _command_generic_msg(self, hostname, result, caption):
|
||||
stdout = result.get('stdout', '').replace('\n', '\\n').replace('\r', '\\r')
|
||||
if 'stderr' in result and result['stderr']:
|
||||
stderr = result.get('stderr','').replace('\n', '\\n').replace('\r', '\\r')
|
||||
stderr = result.get('stderr', '').replace('\n', '\\n').replace('\r', '\\r')
|
||||
return "%s | %s | rc=%s | (stdout) %s (stderr) %s" % (hostname, caption, result.get('rc', -1), stdout, stderr)
|
||||
else:
|
||||
return "%s | %s | rc=%s | (stdout) %s" % (hostname, caption, result.get('rc', -1), stdout)
|
||||
|
@ -49,26 +49,25 @@ class CallbackModule(CallbackBase):
|
|||
error = result._result['exception'].strip().split('\n')[-1]
|
||||
msg = "An exception occurred during task execution. To see the full traceback, use -vvv. The error was: %s" % error
|
||||
else:
|
||||
msg = "An exception occurred during task execution. The full traceback is:\n" + result._result['exception'].replace('\n','')
|
||||
msg = "An exception occurred during task execution. The full traceback is:\n" + result._result['exception'].replace('\n', '')
|
||||
|
||||
if result._task.action in C.MODULE_NO_JSON and 'module_stderr' not in result._result:
|
||||
self._display.display(self._command_generic_msg(result._host.get_name(), result._result,'FAILED'), color=C.COLOR_ERROR)
|
||||
self._display.display(self._command_generic_msg(result._host.get_name(), result._result, 'FAILED'), color=C.COLOR_ERROR)
|
||||
else:
|
||||
self._display.display(msg, color=C.COLOR_ERROR)
|
||||
|
||||
self._display.display("%s | FAILED! => %s" % (result._host.get_name(), self._dump_results(result._result, indent=0).replace('\n','')),
|
||||
self._display.display("%s | FAILED! => %s" % (result._host.get_name(), self._dump_results(result._result, indent=0).replace('\n', '')),
|
||||
color=C.COLOR_ERROR)
|
||||
|
||||
def v2_runner_on_ok(self, result):
|
||||
if result._task.action in C.MODULE_NO_JSON:
|
||||
self._display.display(self._command_generic_msg(result._host.get_name(), result._result,'SUCCESS'), color=C.COLOR_OK)
|
||||
self._display.display(self._command_generic_msg(result._host.get_name(), result._result, 'SUCCESS'), color=C.COLOR_OK)
|
||||
else:
|
||||
self._display.display("%s | SUCCESS => %s" % (result._host.get_name(), self._dump_results(result._result, indent=0).replace('\n','')),
|
||||
self._display.display("%s | SUCCESS => %s" % (result._host.get_name(), self._dump_results(result._result, indent=0).replace('\n', '')),
|
||||
color=C.COLOR_OK)
|
||||
|
||||
|
||||
def v2_runner_on_unreachable(self, result):
|
||||
self._display.display("%s | UNREACHABLE!: %s" % (result._host.get_name(), result._result.get('msg','')), color=C.COLOR_UNREACHABLE)
|
||||
self._display.display("%s | UNREACHABLE!: %s" % (result._host.get_name(), result._result.get('msg', '')), color=C.COLOR_UNREACHABLE)
|
||||
|
||||
def v2_runner_on_skipped(self, result):
|
||||
self._display.display("%s | SKIPPED" % (result._host.get_name()), color=C.COLOR_SKIP)
|
||||
|
|
|
@ -25,11 +25,12 @@ import os
|
|||
|
||||
from ansible.plugins.callback import CallbackBase
|
||||
|
||||
FAILED_VOICE="Zarvox"
|
||||
REGULAR_VOICE="Trinoids"
|
||||
HAPPY_VOICE="Cellos"
|
||||
LASER_VOICE="Princess"
|
||||
SAY_CMD="/usr/bin/say"
|
||||
FAILED_VOICE = "Zarvox"
|
||||
REGULAR_VOICE = "Trinoids"
|
||||
HAPPY_VOICE = "Cellos"
|
||||
LASER_VOICE = "Princess"
|
||||
SAY_CMD = "/usr/bin/say"
|
||||
|
||||
|
||||
class CallbackModule(CallbackBase):
|
||||
"""
|
||||
|
@ -48,7 +49,7 @@ class CallbackModule(CallbackBase):
|
|||
# ansible will not call any callback if disabled is set to True
|
||||
if not os.path.exists(SAY_CMD):
|
||||
self.disabled = True
|
||||
self._display.warning("%s does not exist, plugin %s disabled" % (SAY_CMD, os.path.basename(__file__)) )
|
||||
self._display.warning("%s does not exist, plugin %s disabled" % (SAY_CMD, os.path.basename(__file__)))
|
||||
|
||||
def say(self, msg, voice):
|
||||
subprocess.call([SAY_CMD, msg, "--voice=%s" % (voice)])
|
||||
|
|
|
@ -37,7 +37,9 @@ t0 = tn = time.time()
|
|||
|
||||
def secondsToStr(t):
|
||||
# http://bytes.com/topic/python/answers/635958-handy-short-cut-formatting-elapsed-time-floating-point-seconds
|
||||
rediv = lambda ll, b: list(divmod(ll[0], b)) + ll[1:]
|
||||
def rediv(ll, b):
|
||||
return list(divmod(ll[0], b)) + ll[1:]
|
||||
|
||||
return "%d:%02d:%02d.%03d" % tuple(reduce(rediv, [[t * 1000, ], 1000, 60, 60]))
|
||||
|
||||
|
||||
|
@ -104,7 +106,7 @@ class CallbackModule(CallbackBase):
|
|||
self.current = task._uuid
|
||||
self.stats[self.current] = {'time': time.time(), 'name': task.get_name()}
|
||||
if self._display.verbosity >= 2:
|
||||
self.stats[self.current][ 'path'] = task.get_path()
|
||||
self.stats[self.current]['path'] = task.get_path()
|
||||
|
||||
def v2_playbook_on_task_start(self, task, is_conditional):
|
||||
self._record_task(task)
|
||||
|
@ -127,7 +129,7 @@ class CallbackModule(CallbackBase):
|
|||
if self.sort_order != 'none':
|
||||
results = sorted(
|
||||
self.stats.items(),
|
||||
key=lambda x:x[1]['time'],
|
||||
key=lambda x: x[1]['time'],
|
||||
reverse=self.sort_order,
|
||||
)
|
||||
|
||||
|
@ -136,7 +138,7 @@ class CallbackModule(CallbackBase):
|
|||
|
||||
# Print the timings
|
||||
for uuid, result in results:
|
||||
msg=u"{0:-<{2}}{1:->9}".format(result['name'] + u' ',u' {0:.02f}s'.format(result['time']), self._display.columns - 9)
|
||||
msg = u"{0:-<{2}}{1:->9}".format(result['name'] + u' ', u' {0:.02f}s'.format(result['time']), self._display.columns - 9)
|
||||
if 'path' in result:
|
||||
msg += u"\n{0:-<{1}}".format(result['path'] + u' ', self._display.columns)
|
||||
self._display.display(msg)
|
||||
|
|
|
@ -106,7 +106,7 @@ class CallbackModule(CallbackBase):
|
|||
lines = text.splitlines()
|
||||
result_lines = []
|
||||
for l in lines:
|
||||
result_lines.append("{}{}".format(' '*indent_level, l))
|
||||
result_lines.append("{}{}".format(' ' * indent_level, l))
|
||||
return '\n'.join(result_lines)
|
||||
|
||||
def _print_diff(self, diff, indent_level):
|
||||
|
@ -121,7 +121,7 @@ class CallbackModule(CallbackBase):
|
|||
diff = dict_diff(diff['before'], diff['after'])
|
||||
if diff:
|
||||
diff = colorize(str(diff), 'changed')
|
||||
print(self._indent_text(diff, indent_level+4))
|
||||
print(self._indent_text(diff, indent_level + 4))
|
||||
|
||||
def _print_host_or_item(self, host_or_item, changed, msg, diff, is_host, error, stdout, stderr):
|
||||
if is_host:
|
||||
|
@ -144,7 +144,7 @@ class CallbackModule(CallbackBase):
|
|||
msg = colorize(msg, color)
|
||||
|
||||
line_length = 120
|
||||
spaces = ' ' * (40-len(name)-indent_level)
|
||||
spaces = ' ' * (40 - len(name) - indent_level)
|
||||
line = "{} * {}{}- {}".format(' ' * indent_level, name, spaces, change_string)
|
||||
|
||||
if len(msg) < 50:
|
||||
|
@ -152,16 +152,16 @@ class CallbackModule(CallbackBase):
|
|||
print("{} {}---------".format(line, '-' * (line_length - len(line))))
|
||||
else:
|
||||
print("{} {}".format(line, '-' * (line_length - len(line))))
|
||||
print(self._indent_text(msg, indent_level+4))
|
||||
print(self._indent_text(msg, indent_level + 4))
|
||||
|
||||
if diff is not None:
|
||||
self._print_diff(diff, indent_level)
|
||||
if stdout is not None:
|
||||
stdout = colorize(stdout, 'failed')
|
||||
print(self._indent_text(stdout, indent_level+4))
|
||||
print(self._indent_text(stdout, indent_level + 4))
|
||||
if stderr is not None:
|
||||
stderr = colorize(stderr, 'failed')
|
||||
print(self._indent_text(stderr, indent_level+4))
|
||||
print(self._indent_text(stderr, indent_level + 4))
|
||||
|
||||
def v2_playbook_on_play_start(self, play):
|
||||
"""Run on start of the play."""
|
||||
|
@ -236,7 +236,7 @@ class CallbackModule(CallbackBase):
|
|||
self.last_skipped = False
|
||||
|
||||
line_length = 120
|
||||
spaces = ' ' * (31-len(result._host.name)-4)
|
||||
spaces = ' ' * (31 - len(result._host.name) - 4)
|
||||
|
||||
line = " * {}{}- {}".format(colorize(result._host.name, 'not_so_bold'),
|
||||
spaces,
|
||||
|
@ -255,4 +255,3 @@ class CallbackModule(CallbackBase):
|
|||
v2_playbook_on_handler_task_start = v2_playbook_on_task_start
|
||||
v2_runner_on_failed = v2_runner_on_ok
|
||||
v2_runner_on_unreachable = v2_runner_on_ok
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@ __metaclass__ = type
|
|||
|
||||
from ansible.plugins.callback.default import CallbackModule as CallbackModule_default
|
||||
|
||||
|
||||
class CallbackModule(CallbackModule_default):
|
||||
|
||||
'''
|
||||
|
|
|
@ -68,7 +68,6 @@ class CallbackModule(CallbackBase):
|
|||
else:
|
||||
self._options = None
|
||||
|
||||
|
||||
super(CallbackModule, self).__init__(display=display)
|
||||
|
||||
if not HAS_PRETTYTABLE:
|
||||
|
|
|
@ -12,6 +12,7 @@ import socket
|
|||
|
||||
from ansible.plugins.callback import CallbackBase
|
||||
|
||||
|
||||
class CallbackModule(CallbackBase):
|
||||
"""
|
||||
logs ansible-playbook and ansible runs to a syslog server in json format
|
||||
|
@ -33,35 +34,33 @@ class CallbackModule(CallbackBase):
|
|||
|
||||
super(CallbackModule, self).__init__()
|
||||
|
||||
self.logger = logging.getLogger('ansible logger')
|
||||
self.logger = logging.getLogger('ansible logger')
|
||||
self.logger.setLevel(logging.DEBUG)
|
||||
|
||||
self.handler = logging.handlers.SysLogHandler(
|
||||
address = (os.getenv('SYSLOG_SERVER','localhost'),
|
||||
int(os.getenv('SYSLOG_PORT',514))),
|
||||
facility= os.getenv('SYSLOG_FACILITY',logging.handlers.SysLogHandler.LOG_USER)
|
||||
address=(os.getenv('SYSLOG_SERVER', 'localhost'), int(os.getenv('SYSLOG_PORT', 514))),
|
||||
facility=os.getenv('SYSLOG_FACILITY', logging.handlers.SysLogHandler.LOG_USER)
|
||||
)
|
||||
self.logger.addHandler(self.handler)
|
||||
self.hostname = socket.gethostname()
|
||||
|
||||
|
||||
def runner_on_failed(self, host, res, ignore_errors=False):
|
||||
self.logger.error('%s ansible-command: task execution FAILED; host: %s; message: %s' % (self.hostname,host,self._dump_results(res)))
|
||||
self.logger.error('%s ansible-command: task execution FAILED; host: %s; message: %s' % (self.hostname, host, self._dump_results(res)))
|
||||
|
||||
def runner_on_ok(self, host, res):
|
||||
self.logger.info('%s ansible-command: task execution OK; host: %s; message: %s' % (self.hostname,host,self._dump_results(res)))
|
||||
self.logger.info('%s ansible-command: task execution OK; host: %s; message: %s' % (self.hostname, host, self._dump_results(res)))
|
||||
|
||||
def runner_on_skipped(self, host, item=None):
|
||||
self.logger.info('%s ansible-command: task execution SKIPPED; host: %s; message: %s' % (self.hostname,host, 'skipped'))
|
||||
self.logger.info('%s ansible-command: task execution SKIPPED; host: %s; message: %s' % (self.hostname, host, 'skipped'))
|
||||
|
||||
def runner_on_unreachable(self, host, res):
|
||||
self.logger.error('%s ansible-command: task execution UNREACHABLE; host: %s; message: %s' % (self.hostname,host,self._dump_results(res)))
|
||||
self.logger.error('%s ansible-command: task execution UNREACHABLE; host: %s; message: %s' % (self.hostname, host, self._dump_results(res)))
|
||||
|
||||
def runner_on_async_failed(self, host, res, jid):
|
||||
self.logger.error('%s ansible-command: task execution FAILED; host: %s; message: %s' % (self.hostname,host,self._dump_results(res)))
|
||||
self.logger.error('%s ansible-command: task execution FAILED; host: %s; message: %s' % (self.hostname, host, self._dump_results(res)))
|
||||
|
||||
def playbook_on_import_for_host(self, host, imported_file):
|
||||
self.logger.info('%s ansible-command: playbook IMPORTED; host: %s; message: imported file %s' % (self.hostname,host,imported_file))
|
||||
self.logger.info('%s ansible-command: playbook IMPORTED; host: %s; message: imported file %s' % (self.hostname, host, imported_file))
|
||||
|
||||
def playbook_on_not_import_for_host(self, host, missing_file):
|
||||
self.logger.info('%s ansible-command: playbook NOT IMPORTED; host: %s; message: missing file %s' % (self.hostname,host,missing_file))
|
||||
self.logger.info('%s ansible-command: playbook NOT IMPORTED; host: %s; message: missing file %s' % (self.hostname, host, missing_file))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue