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