Skip to content

Commit

Permalink
setup real log format fix
Browse files Browse the repository at this point in the history
  • Loading branch information
guohongze committed Mar 13, 2019
1 parent eaba721 commit 443b3fa
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
12 changes: 7 additions & 5 deletions setup/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ def ansible_task(request, host, group, pbook, roles, role_vars, write_role_vars)
for d in data:
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(data)
else:
for h in host:
Expand All @@ -81,8 +81,8 @@ def ansible_task(request, host, group, pbook, roles, role_vars, write_role_vars)
data = pcmd.communicate()
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(data)
for d in data:
logging.info(d)
Expand Down Expand Up @@ -110,8 +110,8 @@ def ansible_task(request, host, group, pbook, roles, role_vars, write_role_vars)
data = p.communicate()
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(data)
for d in data:
logging.info(d)
Expand All @@ -129,8 +129,8 @@ def ansible_task(request, host, group, pbook, roles, role_vars, write_role_vars)
data = pcmd.communicate()
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(data)
for d in data:
logging.info(d)
Expand All @@ -156,8 +156,9 @@ def shell_task(request, server, group, scripts, args, shell_command):
ret.append(host.hostname)
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")

for s in scripts:
try:
sh.scp(scripts_dir+s, "root@{}:/tmp/".format(host.ip)+s)
Expand All @@ -179,6 +180,7 @@ def shell_task(request, server, group, scripts, args, shell_command):
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("=================================\n")
for cmd in command_list:
dcmd = "ssh root@"+host.ip+" "+'"{}"'.format(cmd.strip())
p = Popen(dcmd, stdout=PIPE, stderr=PIPE, shell=True)
Expand Down
2 changes: 1 addition & 1 deletion templates/setup/shell.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
<div class="box-body">
<div class="row">

<div class="col-md-6">
<div class="col-md-5">
<form action="#" method="post" id="form1">
{% csrf_token %}
<div class="form-group">
Expand Down

0 comments on commit 443b3fa

Please sign in to comment.