在python中我试图执行fabfile,我从subproccess输出中得到以下错误。我使用简易安装安装了面料。如果我从命令行运行代码它可以工作。从python没有去。我假设我如何使用Popen命令有问题?
/bin/sh: 1: fab: not found
以下是我从python启动fabric的方法:
cmd = """fab -H 111.111.111.111 aws_bootstrap initial_chef_run:aws_server.json,aws-test,development -w """
os.chdir(fab_path) #change to the dir where the fabfile is located
p = subprocess.Popen(cmd, shell=True,stderr=subprocess.STDOUT,stdout=subprocess.PIPE)
PS我将下面的内容添加到Popen中,但得到以下错误:
executable="/bin/bash"
/bin/bash: fab: command not found
从命令行我得到以下内容,这意味着终端可以找到fab。
fab
Fatal error: Couldn't find any fabfiles!
Remember that -f can be used to specify fabfile path, and use -h for help.
Aborting.
答案 0 :(得分:0)
尝试使用fab的整个路径。要在系统上获取fab的路径,可以使用which fab
。
但是,我想不出有什么理由为什么从python调用fab可能比使用fab的execute函数更好:
from fabric.tasks import execute
import my_fabfile
r = execute(my_fabfile.aws_bootstrap, hosts=["root@%s" % '111.111.111.111])
返回值r将包含一个以主机为键的dict。