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 @@ ...@@ -2,8 +2,9 @@
import os import os
import time import time
import json import json
from ansible.plugins.callback import CallbackBase
class CallbackModule(object): class CallbackModule(CallbackBase):
""" """
logs playbook results, per host, in /var/log/ansible/hosts logs playbook results, per host, in /var/log/ansible/hosts
""" """
...@@ -12,6 +13,8 @@ class CallbackModule(object): ...@@ -12,6 +13,8 @@ class CallbackModule(object):
def __init__(self): def __init__(self):
super(CallbackModule, self).__init__()
if not os.path.exists(self.log_path): if not os.path.exists(self.log_path):
os.makedirs(self.log_path) os.makedirs(self.log_path)
else: else:
...@@ -21,6 +24,7 @@ class CallbackModule(object): ...@@ -21,6 +24,7 @@ class CallbackModule(object):
os.unlink(filepath) os.unlink(filepath)
def log(self, host, category, data, ignore_errors=False): def log(self, host, category, data, ignore_errors=False):
if type(data) == dict: if type(data) == dict:
if '_ansible_verbose_override' in data: if '_ansible_verbose_override' in data:
# avoid logging extraneous data # avoid logging extraneous data
...@@ -30,7 +34,7 @@ class CallbackModule(object): ...@@ -30,7 +34,7 @@ class CallbackModule(object):
data = json.dumps(data) data = json.dumps(data)
if ignore_errors: if ignore_errors:
category = '%s_INGORED' % category category = '%s_IGNORED' % category
path = os.path.join("/var/log/ansible/hosts", '%s_%s' % (host, category)) path = os.path.join("/var/log/ansible/hosts", '%s_%s' % (host, category))
with open(path, "a") as fd: with open(path, "a") as fd:
fd.write(data) 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