在本地运行结构脚本
我有一个 django 应用程序,我编写了一个结构脚本,用于在部署服务器(Cent OS 5)上安装我的应用程序。
现在我想在部署服务器上本地运行相同的结构脚本。
有没有办法在不提供 ssh 用户和密码的情况下完成此操作?
我的意思是只用“-H localhost”?
谢谢,亚历克斯·A.
I have a django app and I wrote a fabric script that installs my app on deployment server (Cent OS 5).
Now I want to run the same fabric script locally on the deployment server.
Is there a way to do it without supplying ssh user and password?
I mean just with "-H localhost"?
Thanks, Alex A.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
是的,您可以使用方法local而不是run在本地运行fab。我通常做的是设置环境的方法,并在调用实际任务之前先调用这些方法。让我用一个针对您的具体问题的示例来说明这一点
fabfile.py
并且根据环境,您可以执行以下操作
在本地主机上安装:
在远程计算机上安装:
Yes, you can run fab locally by using method local instead of run. What I do typically is have methods for setting up the environment, and call these methods first before calling the actual task. Let me illustrate this with an example for your specific question
fabfile.py
And based on the environment, you can do the following
Install on localhost:
Install on remote machine:
我正在使用另一个技巧在本地执行远程任务:
I am using another trick for executing remote task locally:
比 Varun 的答案 稍微不那么优雅,但默认在本地计算机上运行可能更实用,除非给出另一个环境选择器。
然后在本地运行为:
或远程运行为:
PS。以下是关于此主题的 Github 问题。
Slightly less elegant than Varun's answer, but maybe more practical by defaulting to run on the local machine unless another environment selector is given.
Then run locally as:
or remotely with:
PS. Here is the Github issue on this topic.
首先,确保您可以在没有密码的情况下 ssh 进入本地主机:
$ ssh-copy-id localhost
然后按照您所说的使用
-H localhost
命令运行它线路选项First, make sure you can ssh into your localhost without a password:
$ ssh-copy-id localhost
And then just run it as you said, with the
-H localhost
command line option您可以在本地计算机上运行 ssh 服务器,以便能够 ssh 到本地主机。然后只需使用“-H localhost”运行脚本即可。非常适合我。
You can run ssh server on your local machine to be able to ssh to localhost. And then just run scripts with "-H localhost". Works perfectly for me.
Varun 的答案的修改版本,考虑到本地不捕获 stdout/stderr。如果不指定 capture=True 您将无法从本地获取结果。
A modified version of Varun's answer that takes into account local not capturing stdout/stderr. Without specifying capture=True you would not be able to get results from local.