callback_plugins: try and run a simple 2to3 over the logdetail plugin

Signed-off-by: Kevin Fenzi <kevin@scrye.com>
This commit is contained in:
Kevin Fenzi 2020-06-04 15:23:41 -07:00
parent 79f8c0e654
commit 0aba558968

View file

@ -15,7 +15,7 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>. # along with Ansible. If not, see <http://www.gnu.org/licenses/>.
from __future__ import absolute_import
import os import os
import time import time
@ -42,7 +42,7 @@ LOG_PATH = '/var/log/ansible'
def getlogin(): def getlogin():
try: try:
user = os.getlogin() user = os.getlogin()
except OSError, e: except OSError as e:
user = pwd.getpwuid(os.geteuid())[0] user = pwd.getpwuid(os.geteuid())[0]
return user return user
@ -56,8 +56,8 @@ class LogMech(object):
self.logpath = LOG_PATH self.logpath = LOG_PATH
if not os.path.exists(self.logpath): if not os.path.exists(self.logpath):
try: try:
os.makedirs(self.logpath, mode=0750) os.makedirs(self.logpath, mode=0o750)
except OSError, e: except OSError as e:
if e.errno != 17: if e.errno != 17:
raise raise
@ -83,7 +83,7 @@ class LogMech(object):
if not os.path.exists(path): if not os.path.exists(path):
try: try:
os.makedirs(path) os.makedirs(path)
except OSError, e: except OSError as e:
if e.errno != 17: # if it is not dir exists then raise it up if e.errno != 17: # if it is not dir exists then raise it up
raise raise
@ -266,16 +266,16 @@ class CallbackModule(CallbackBase):
try: try:
logmech.play_log(json.dumps(info, indent=4)) logmech.play_log(json.dumps(info, indent=4))
except TypeError: except TypeError:
print("Failed to conver to JSON:", info) print(("Failed to conver to JSON:", info))
def v2_playbook_on_stats(self, stats): def v2_playbook_on_stats(self, stats):
results = {} results = {}
for host in stats.processed.keys(): for host in list(stats.processed.keys()):
results[host] = stats.summarize(host) results[host] = stats.summarize(host)
logmech.log(host, 'STATS', results[host]) logmech.log(host, 'STATS', results[host])
logmech.play_log(json.dumps({'stats': results}, indent=4)) logmech.play_log(json.dumps({'stats': results}, indent=4))
logmech.play_log(json.dumps({'playbook_end': time.time()}, indent=4)) logmech.play_log(json.dumps({'playbook_end': time.time()}, indent=4))
print('logs written to: %s' % logmech.logpath_play) print(('logs written to: %s' % logmech.logpath_play))