Commit 8be34213 authored by Thomas Gambier's avatar Thomas Gambier 🚴🏼

slapos_web_deploy: log_parse callback supports newer version of ansible

1) when ansible is still python2 and the callback "json" was introduced
(e.g. in Ubuntu 18.04) we need to use "strict_import" to be sure to use
the json python module and not the json callback

2) when ansible is python3 the syntax must be python3 compatible

3) also remove an uneeded data.copy()
parent e6deadac
......@@ -163,6 +163,7 @@ fi
ANSIBLE_PLUGIN_LOCATION="/usr/share/ansible_plugins/callback_plugins/"
mkdir -p $ANSIBLE_PLUGIN_LOCATION
/bin/cat << EOF > $ANSIBLE_PLUGIN_LOCATION/log_parse.py
from __future__ import absolute_import
import os
import time
import json
......@@ -192,11 +193,11 @@ class CallbackModule(baseModule):
else:
for filename in os.listdir(self.log_path):
filepath = os.path.join(self.log_path, filename)
if os.path.exists(filepath) and os.path.isfile(filepath):
if os.path.isfile(filepath):
os.unlink(filepath)
def writeLog(self, host, category, content):
if not self.fd_list.has_key(category):
if category not in self.fd_list:
self.fd_list[category] = open(
os.path.join(self.log_path, '%s_%s' % (host, category)), "a"
)
......@@ -207,12 +208,11 @@ class CallbackModule(baseModule):
if host == "localhost":
host = "127.0.0.1" # keep compatibility
if type(data) == dict:
if type(data) is dict:
if '_ansible_verbose_override' in data:
# avoid logging extraneous data
return
data = data.copy()
content = json.dumps(data)
if ignore_errors:
......
/bin/cat << EOF > $ANSIBLE_PLUGIN_LOCATION/log_parse.py
from __future__ import absolute_import
import os
import time
import json
......@@ -28,11 +29,11 @@ class CallbackModule(baseModule):
else:
for filename in os.listdir(self.log_path):
filepath = os.path.join(self.log_path, filename)
if os.path.exists(filepath) and os.path.isfile(filepath):
if os.path.isfile(filepath):
os.unlink(filepath)
def writeLog(self, host, category, content):
if not self.fd_list.has_key(category):
if category not in self.fd_list:
self.fd_list[category] = open(
os.path.join(self.log_path, '%s_%s' % (host, category)), "a"
)
......@@ -43,12 +44,11 @@ class CallbackModule(baseModule):
if host == "localhost":
host = "127.0.0.1" # keep compatibility
if type(data) == dict:
if type(data) is dict:
if '_ansible_verbose_override' in data:
# avoid logging extraneous data
return
data = data.copy()
content = json.dumps(data)
if ignore_errors:
......
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