[英]How do I execute a fabfile from my python script?
I have a fabfile and here are the contents: 我有一个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')
I can execute the fabfile successfully when it is run from the command line like so: 当从命令行运行fabfile时,我可以成功执行它,如下所示:
fab -f fabfile.py -u ec2-user -i id_rsa -H 10.10.15.242 deploy
The problem is that it it does not work when I run it from within my Python script. 问题是,当我从Python脚本中运行它时,它不起作用。 This is how it is run within my script: 这是在我的脚本中运行的方式:
import subprocess
subprocess.call(['fab', '-f', '/home/myhome/scripts/bakery/fabfile.py', '-u ec2-user', '-i', 'id_rsa', '-H', bakery_internalip, 'deploy'])
This is the error which I am getting: 这是我得到的错误:
Fatal error: Fabfile didn't contain any commands!
Aborting.
I don't understand why I am getting this error. 我不明白为什么会收到此错误。
Change fabfile.py and add these few changes. 更改fabfile.py并添加一些更改。
@task
def deploy():
... rest of the code
if __name__ == "__main__":
local('fab -f /path/fabfile.py deploy')
Then run it in python 然后在python中运行它
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.