Commit ddb01dec authored by Alain Takoudjou's avatar Alain Takoudjou Committed by Rafael Monnerat

Make Ansible log_parse callback plugins compatible with version 2

parent 76b94485
......@@ -2,8 +2,9 @@
import os
import time
import json
from ansible.plugins.callback import CallbackBase
class CallbackModule(object):
class CallbackModule(CallbackBase):
"""
logs playbook results, per host, in /var/log/ansible/hosts
"""
......@@ -12,6 +13,8 @@ class CallbackModule(object):
def __init__(self):
super(CallbackModule, self).__init__()
if not os.path.exists(self.log_path):
os.makedirs(self.log_path)
else:
......@@ -21,6 +24,7 @@ class CallbackModule(object):
os.unlink(filepath)
def log(self, host, category, data, ignore_errors=False):
if type(data) == dict:
if '_ansible_verbose_override' in data:
# avoid logging extraneous data
......@@ -30,7 +34,7 @@ class CallbackModule(object):
data = json.dumps(data)
if ignore_errors:
category = '%s_INGORED' % category
category = '%s_IGNORED' % category
path = os.path.join("/var/log/ansible/hosts", '%s_%s' % (host, category))
with open(path, "a") as fd:
fd.write(data)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment