Skip to content

Commit

Permalink
setup tasks log format fix
Browse files Browse the repository at this point in the history
  • Loading branch information
guohongze committed Mar 13, 2019
1 parent 1955570 commit eaba721
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions setup/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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

0 comments on commit eaba721

Please sign in to comment.