Can anyone help with below . Its not yet solved for me . On Wednesday, February 3, 2016 at 8:05:31 PM UTC+5:30, Ankit Kulkarni wrote: > > > On Wednesday, February 3, 2016 at 7:41:53 PM UTC+5:30, J Hawkesworth wrote: >> >> 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 >> >> On Wednesday, 3 February 2016 13:48:38 UTC, [email protected] wrote: >>> >>> 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 . > >> >>> On Wednesday, February 3, 2016 at 4:23:05 PM UTC+3, Ankit Kulkarni wrote: >>>> >>>> We are using ansible in our production and our log_plays callback >>>> plugin just broke after upgrading from 1.9.4 to 2.0.0.1 . >>>> >>>> I need to put my custom logging using log_plays.py ( say store the >>>> results in a sqllitedb for later analysis ) . The same was working fine >>>> till ansible 1.9.4 . I am using *ansible 2.0.0 on ubuntu 14.04 64 bit >>>> . * >>>> >>>> I used this log file >>>> https://github.com/ansible/ansible/blob/stable-2.0.0.1/lib/ansibale/plugins/callback/log_plays.py >>>> >>>> . Any function overrided under the `class CallbackModule(CallbackBase):` >>>> are not reflecting while the code outside class is working . >>>> >>>> Example - >>>> >>>> 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 . >>>> >>>> >>>> >>>>
-- 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 [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/41a580e5-7885-470d-91d5-84e3c8ce1c0e%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
