与 Python 脚本一起运行 Fabric
我看到大多数 Fabric API 都是与函数一起使用的。
文件示例(sample.py):
from fabric.api import *
print "Hello"
def deploy():
with settings(hosts_string="Remote", user = "ubuntu", key_filename="/home/ubuntu/key.pem"):
put('/home/localuser/sample.sh', '/home/ubuntu/')
run('bash /home/ubuntu/sample.sh')
我运行命令来执行
fab deploy
是否可以在主方法中运行 Fabric。因此,当我将其作为 python 脚本运行时,该结构将被执行。
python ./sample.py
谢谢!
I see most of the Fabric API are use together with function.
Example of file (sample.py):
from fabric.api import *
print "Hello"
def deploy():
with settings(hosts_string="Remote", user = "ubuntu", key_filename="/home/ubuntu/key.pem"):
put('/home/localuser/sample.sh', '/home/ubuntu/')
run('bash /home/ubuntu/sample.sh')
I run the command to execute
fab deploy
Is it possible to running Fabric in Main Method. So when I run it as a python script, the fabric will be executed.
python ./sample.py
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
要直接回答您的问题,您可以将此代码段添加到您的文件中:
现在,当您运行
python ./sample.py
时,它将执行与fab deploy
相同的操作但是,除了简单的示例之外,
fab
还允许您执行更多操作。有关 fab 灵活性的更多信息,请参阅 fab 文档代码>命令。To answer your question directly, you can add this snippet to your file:
Now when you run
python ./sample.py
, it will do the same thing asfab deploy
However, the
fab
allows you to do much more other than your simple example. See the fab documentation for more information on the flexibility of thefab
command.你必须给出fabric的执行命令。在最底层执行(部署)
You have to give fabric's execute command. At the very bottom execute(deploy)