From eaba7210ff66ad550c8e4a105a6c87329e2385e9 Mon Sep 17 00:00:00 2001 From: guohongze Date: Wed, 13 Mar 2019 10:58:20 +0800 Subject: [PATCH] setup tasks log format fix --- setup/tasks.py | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/setup/tasks.py b/setup/tasks.py index 565ced97..b7d9f325 100644 --- a/setup/tasks.py +++ b/setup/tasks.py @@ -65,8 +65,7 @@ def ansible_task(request, host, group, pbook, roles, role_vars, write_role_vars) logging.info(d) with open(log_path + "/execlog/ansible_{0}.log".format(request.user.username), 'ab+') as f1: f1.writelines("===============================\n") - f1.writelines("Host: {0}\n".format(h)) - f1.writelines("===============================\n") + f1.writelines("***Host: {0} ***\n".format(h)) f1.writelines(data) else: for h in host: @@ -83,8 +82,7 @@ def ansible_task(request, host, group, pbook, roles, role_vars, write_role_vars) ret.append(data) with open(log_path + "/execlog/ansible_{0}.log".format(request.user.username), 'ab+') as f2: f2.writelines("===============================\n") - f2.writelines("Host: {0}\n".format(h)) - f2.writelines("===============================\n") + f2.writelines("*** Host: {0} ***\n".format(h)) f2.writelines(data) for d in data: logging.info(d) @@ -113,8 +111,7 @@ def ansible_task(request, host, group, pbook, roles, role_vars, write_role_vars) ret.append(data) with open(log_path + "/execlog/ansible_{0}.log".format(request.user.username), 'ab+') as f4: f4.writelines("===============================\n") - f4.writelines("Group: {0}\n".format(g)) - f4.writelines("===============================\n") + f4.writelines("*** Group: {0} ***\n".format(g)) f4.writelines(data) for d in data: logging.info(d) @@ -133,8 +130,7 @@ def ansible_task(request, host, group, pbook, roles, role_vars, write_role_vars) ret.append(data) with open(log_path + "/execlog/ansible_{0}.log".format(request.user.username), 'ab+') as f5: f5.writelines("===============================\n") - f5.writelines("Group: {0}\n".format(g)) - f5.writelines("===============================\n") + f5.writelines("*** Group: {0} ***\n".format(g)) f5.writelines(data) for d in data: logging.info(d) @@ -161,8 +157,7 @@ def shell_task(request, server, group, scripts, args, shell_command): logging.info("Host:"+host.hostname) with open(log_path + "/execlog/shell_{0}.log".format(request.user.username), 'ab+') as f7: f7.writelines("===============================\n") - f7.writelines("Host: {0}\n".format(host.hostname)) - f7.writelines("===============================\n") + f7.writelines("*** Host: {0} ***\n".format(host.hostname)) for s in scripts: try: sh.scp(scripts_dir+s, "root@{}:/tmp/".format(host.ip)+s) @@ -183,7 +178,7 @@ def shell_task(request, server, group, scripts, args, shell_command): ret.append(host.hostname) command_list = shell_command.split('\n') with open(log_path + "/execlog/shell_{0}.log".format(request.user.username), 'ab+') as f8: - f8.writelines("=====Host: {0}=====\n".format(host.hostname)) + f8.writelines("*** Host: {0} ***\n".format(host.hostname)) for cmd in command_list: dcmd = "ssh root@"+host.ip+" "+'"{}"'.format(cmd.strip()) p = Popen(dcmd, stdout=PIPE, stderr=PIPE, shell=True) @@ -239,7 +234,7 @@ def shell_task(request, server, group, scripts, args, shell_command): for d in data: logging.info(d) with open(log_path + "/execlog/shell_{0}.log".format(request.user.username), 'ab+') as f6: - f6.writelines("==========Shell Tasks Finished==========") - logging.info("==========Shell Tasks Finished==========") + f6.writelines("==========Shell Tasks Finished========") + logging.info("==========Shell Tasks Finished========") res.set("shell_{0}".format(request.user.username), 0) return True \ No newline at end of file