当我运行python代码时,它要求主机。
No hosts found. Please specify (single) host string for connection:
我有以下代码:
from fabric.api import *
from fabric.contrib.console import confirm
env.hosts = [ 'ipaddress' ]
def remoteRun():
print "ENV %s" %(env.hosts)
out = run('uname -r')
print "Output %s"%(out)
remoteRun();
我甚至试着用-H选项运行fab,得到了同样的信息。我正在使用Ubuntu10.10任何帮助都是值得感谢的。顺便说一句,我是个Python新手。
如果只有一个主机,则可以使用
env.host_string = 'somehost or ipaddress'
。你也不需要在你的
remoteRun
末尾加上;
。我不太确定在您的示例中,
remoteRun();
应该做什么。它是fabfile的一部分还是调用脚本的终端命令?
正确的方法是在shell中使用这样的命令:
fab remoteRun
通常,最好指定您的命令应该在其上运行的具体主机,如下所示:
您可以从终端这样运行它(假设您在包含fabfile的目录中):
另外,还可以使用-H参数指定主机:
如果有要为其调用命令的主机列表,请按如下方式执行: http://readthedocs.org/docs/fabric/latest/usage/execution.html
根据您的示例调整:
并通过
fab remoteRun
调用这样
remoteRun
在env.hosts
中的所有主机上执行。为了让主机在fab命令行工具和fabfile.py之外的脚本中工作,you'll have to use execute():
相关问题 更多 >
编程相关推荐