Yes the internal ansible APIs have changed in v2
Have a look at the other plugins in your ansible installation.
For example
site-packages/ansible/plugins/callback/timer.py
You 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
I believe you should use ‘v2_’ versions of functions in 2.0
Thanks a lot guys . I used the ‘v2_’ versions of the functions however it still couldn’t work. I have the following below code . Is something wrong in it
`
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)
`
It still didn’t overrided .