我正在使用下面的Fabric脚本在远程主机上运行,该主机基本上调用python脚本/hm/it_script/DC/scripts/mainRun.py
并在文件上收集输出。我正在使用sudo用户连接到远程主机。
下面的代码有效,但返回一些警告和错误。
import sys
from fabric.api import env
from fabric.operations import sudo
from fabric.api import settings
env.skip_bad_hosts=True
env.command_timeout=120
env.user = 'trooper'
env.shell = "/bin/sh -c"
env.warn_only = True
env.password = 'pass4321'
def read_hosts():
env.hosts = [line.strip() for line in sys.stdin.readlines()]
def system_Health():
with settings(warn_only=True):
output=sudo("/hm/it_script/DC/scripts/mainRun.py", shell=False)
Warning: One or more hosts failed while executing task 'system_Health'
Warning: sudo() received nonzero return code 1 while executing '/hm/it_script/DC/scripts/mainRun.py'!
Warning: sudo() received nonzero return code 127 while executing '/hm/it_script/DC/scripts/mainRun.py'!
Warning: sudo() received nonzero return code 127 while executing '/hm/it_script/DC/scripts/mainRun.py'!
Fatal error: Needed to prompt for a connection or sudo password (host: server02), but input would be ambiguous in parallel mode Aborting.
Fatal error: Needed to prompt for a connection or sudo password (host: server01), but input would be ambiguous in parallel mode Aborting.
如何避免这些错误或警告,请多多指教和帮助。
织物版本:1.14