diff --git a/run_websocket.py b/run_websocket.py
index 4a1a185dc..ec6b2f73f 100755
--- a/run_websocket.py
+++ b/run_websocket.py
@@ -230,15 +230,14 @@ class ExecHandler(tornado.websocket.WebSocketHandler):
def on_message(self, message):
data = json.loads(message)
pattern = data.get('pattern', '')
- command = data.get('command', '')
- asset_name_str = ''
- if pattern and command:
+ self.command = data.get('command', '')
+ self.asset_name_str = ''
+ if pattern and self.command:
for inv in self.runner.inventory.get_hosts(pattern=pattern):
- asset_name_str += '%s ' % inv.name
- self.write_message('匹配主机: ' + asset_name_str)
- self.write_message('Ansible> %s\n\n' % command)
- self.__class__.tasks.append(MyThread(target=self.run_cmd, args=(command, pattern)))
- ExecLog(host=asset_name_str, cmd=command, user=self.user.username, remote_ip=self.remote_ip).save()
+ self.asset_name_str += '%s ' % inv.name
+ self.write_message('匹配主机: ' + self.asset_name_str)
+ self.write_message('Ansible> %s\n\n' % self.command)
+ self.__class__.tasks.append(MyThread(target=self.run_cmd, args=(self.command, pattern)))
for t in self.__class__.tasks:
if t.is_alive():
@@ -251,11 +250,12 @@ class ExecHandler(tornado.websocket.WebSocketHandler):
def run_cmd(self, command, pattern):
self.runner.run('shell', command, pattern=pattern)
+ ExecLog(host=self.asset_name_str, cmd=self.command, user=self.user.username,
+ remote_ip=self.remote_ip, result=self.runner.results).save()
newline_pattern = re.compile(r'\n')
for k, v in self.runner.results.items():
for host, output in v.items():
output = newline_pattern.sub('
', output)
- logger.debug(output)
if k == 'ok':
header = "[ %s => %s]\n" % (host, 'Ok')
else: