def runner_on_ok(self, host, res):
self.log(host, 'ok-it-worked', res)I wanted to use the playbook_on_stats(self, stats) function . How can I use it ? I can see the changes from the 1.9.4 log_plays.py file https://github.com/ansible/ansible/blob/stable-1.9/plugins/callbacks/log_plays.py like now not all functions are included but not getting why the functions are not overriding .
Yes the internal ansible APIs have changed in v2Have a look at the other plugins in your ansible installation.For examplesite-packages/ansible/plugins/callback/timer.pyYou will notice that the plugins now subclass CallbackModule.Another change in Ansible 2.0 is that you can just whitelist the plugins that you want to use in your ansible.cfg, rather than having to copy them to somewhere on your plugin path.Hope this helps,Jon
On Wednesday, 3 February 2016 13:48:38 UTC, tiny...@gmail.com wrote:I believe you should use 'v2_' versions of functions in 2.0
class CallbackModule(CallbackBase):
"""
logs playbook results, per host, in /var/log/ansible/hosts
"""
CALLBACK_VERSION = 2.0
CALLBACK_TYPE = 'notification'
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"
def __init__(self):
super(CallbackModule, self).__init__()
if not os.path.exists("/var/log/ansible/hosts"):
os.makedirs("/var/log/ansible/hosts")
def log(self, host, category, data):
if type(data) == dict:
if '_ansible_verbose_override' in data:
# avoid logging extraneous data
data = 'omitted'
else:
data = data.copy()
invocation = data.pop('invocation', None)
data = json.dumps(data)
if invocation is not None:
data = json.dumps(invocation) + " => %s " % data
path = os.path.join("/var/log/ansible/hosts", host)
now = time.strftime(self.TIME_FORMAT, time.localtime())
msg = to_bytes(self.MSG_FORMAT % dict(now=now, category=category, data=data))
with open(path, "ab") as fd:
fd.write(msg)
def v2_runner_on_failed(self, host, res, ignore_errors=False):
self.log(host, 'FAILED', res)
def v2_runner_on_ok(self, host, res):
self.log(host, 'OKkkkk', res)
def v2_runner_on_skipped(self, host, item=None):
self.log(host, 'SKIPPED', '...')
def v2_runner_on_unreachable(self, host, res):
self.log(host, 'UNREACHABLE', res)
def v2_runner_on_async_failed(self, host, res, jid):
self.log(host, 'ASYNC_FAILED', res)
def v2_playbook_on_import_for_host(self, host, imported_file):
self.log(host, 'IMPORTED', imported_file)
def v2_playbook_on_not_import_for_host(self, host, missing_file):
self.log(host, 'NOTIMPORTED', missing_file)
Thanks a lot Brian . It solved my issue. I was missing callback whitelist in ansible.cfg
In ansible 1.9 didn't required callback to whitelist. They used to run with default config.
Thanks a lot for the help .
--
You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/uxJ1TNpZzTM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAJ5XC8kEGoHYzaF-KSSn%3DTyHxEaROv05c%3D%2BPaoS1sz7FGUBUxw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAB2OGWwJ9gq5mLwoQdoYKgM_dHzaSJ-kWFmCQOdtmqNCk7zpaA%40mail.gmail.com.