我有一个fabfile,以下是内容:
[root@ip-10-10-20-82 bakery]# cat fabfile.py
from fabric.api import run
def deploy():
run('wget -P /tmp https://s3.amazonaws.com/LinuxBakery/httpd-2.2.26-1.1.amzn1.x86_64.rpm')
run('sudo yum localinstall /tmp/httpd-2.2.26-1.1.amzn1.x86_64.rpm')
我可以在命令行运行时成功执行fabfile,如下所示:
fab -f fabfile.py -u ec2-user -i id_rsa -H 10.10.15.242 deploy
问题是当我从Python脚本中运行它时,它不起作用。这就是我在脚本中运行的方式:
import subprocess
subprocess.call(['fab', '-f', '/home/myhome/scripts/bakery/fabfile.py', '-u ec2-user', '-i', 'id_rsa', '-H', bakery_internalip, 'deploy'])
这是我得到的错误:
Fatal error: Fabfile didn't contain any commands!
Aborting.
我不明白为什么会收到此错误。
答案 0 :(得分:0)
更改fabfile.py并添加这些更改。
@task
def deploy():
... rest of the code
if __name__ == "__main__":
local('fab -f /path/fabfile.py deploy')
然后在python
中运行它