def run_command(self, ecommand, host):
"""Run single stored command"""
command = ecommand['command']
# Check to see if host can run command
if not command.can_host_use(host):
if not command.suppress_limit_to_hosts_warnings:
logger.warn("Invalid host for command",
command=command.name,
hostname=host.hostname,
module=COMMAND_MODULE_INIT,
allowed_hosts=command.limit_to_hosts)
return False
# Call root is already taken applied in get_cmd
ssh_run = SshRun(host.hostname, host.ssh_hostname, "",
helpers.get_function_name(), False)
logger.info("SSH Started",
state=0,
hostname=host.hostname,
command=command.name,
module=COMMAND_MODULE_CUSTOM)
results = ssh_run.run_single(self.get_cmd(ecommand))
ssh_run.close_ssh_channel()
_log_rc(results,
"SSH Finished",
state=1,
auth=command.use_auth,
app_binary=command.use_app_binary,
hostname=host.hostname,
command=command.name,
cmd=self.get_cmd_clean(ecommand),
output=results,
module=COMMAND_MODULE_CUSTOM)
return True
评论列表
文章目录