使用 Fabric 时连接到 ~/.ssh/config 中列出的主机
我在使用 Fabric
无法识别 ~/.ssh/config
中的主机。
我的 fabfile.py 如下:
from fabric.api import run, env
env.hosts = ['lulu']
def whoami():
run('whoami')
运行 $ fab whoami 给出:
[lulu]运行:whoami
致命错误:名称查找失败 露露
名称 lulu
位于我的 ~/.ssh/config
中,如下所示:
Host lulu
hostname 192.168.100.100
port 2100
IdentityFile ~/.ssh/lulu-key
我解决此问题的第一个想法是添加类似 lulu.lulu
的内容> 到 /etc/hosts
(我在 Mac 上),但随后我还必须将身份文件传递给 Fabric - 而且我宁愿保留我的身份验证(即 ~ /.ssh/config
)与我的部署(即fabfile.py
)分开。
另外,顺便说一句,如果您尝试连接到主机文件中的主机,fabric.contrib.projects.rsync_project
似乎不承认 hosts.env< 中的“端口” /code> (即,如果您使用
hosts.env = [lulu:2100]
调用 rsync_project
似乎会尝试连接到 lulu:21
)。
Fabric 无法识别这个 lulu
名称是否有原因?
I'm having trouble with Fabric
not recognizing hosts that I have in ~/.ssh/config
.
My fabfile.py
is as follows:
from fabric.api import run, env
env.hosts = ['lulu']
def whoami():
run('whoami')
Running $ fab whoami
gives:
[lulu] run: whoami
Fatal error: Name lookup failed for
lulu
The name lulu
is in my ~/.ssh/config
, like this:
Host lulu
hostname 192.168.100.100
port 2100
IdentityFile ~/.ssh/lulu-key
My first thought to solving this is adding something like lulu.lulu
to /etc/hosts
(I'm on a Mac), but then I have to also pass in the identity file to Fabric - and I'd rather keep my authentication (i.e. ~/.ssh/config
) separate from my deployment (i.e. fabfile.py
).
As well, incidentally, if you try to connect to a host in the hosts file, fabric.contrib.projects.rsync_project
doesn't seem to acknowledge 'ports' in the hosts.env
(i.e. if you use hosts.env = [lulu:2100]
a call to rsync_project
seems to try connecting to lulu:21
).
Is there a reason Fabric doesn't recognize this lulu
name?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
从版本 1.4.0 开始,Fabric 使用您的 ssh 配置(部分)。但是,您需要在
fabfile 顶部附近的某个位置显式启用它。执行此操作后,Fabric 应该读取您的 ssh 配置(默认从
~/.ssh/config
或从env.ssh_config_path
)。一个警告:如果您使用早于 1.5.4 的版本,并且设置了
env.use_ssh_config
但不存在配置文件,则会发生中止。在这种情况下,您可以使用如下解决方法:Since version 1.4.0, Fabric uses your ssh config (partly). However, you need to explicitly enable it, with
somewhere near the top of your fabfile. Once you do this, Fabric should read your ssh config (from
~/.ssh/config
by default, or fromenv.ssh_config_path
).One warning: if you use a version older than 1.5.4, an abort will occur if
env.use_ssh_config
is set but there is no config file present. In that case, you can use a workaround like:请注意,当名称不在
/etc/hosts
中时也会发生这种情况。我遇到了同样的问题,必须将主机名添加到该文件和~/.ssh/config
中。Note that this also happens when the name is not in
/etc/hosts
. I had the same problem and had to add the host name to both that file and~/.ssh/config
.更新:此答案现已过时。
Fabric 目前不支持 .ssh/config 文件。您可以在函数中设置它们,然后在 cli 上调用,例如:fab 生产任务;其中 Production 设置用户名、主机名、端口和 ssh 身份。
至于 rsync 项目,现在应该具有端口设置能力,如果没有,您可以随时运行 local("rsync ..."),因为这本质上就是贡献函数的作用。
update: This Answer is now outdated.
Fabric doesn't have support currently for the .ssh/config file. You can set these up in a function to then call on the cli, eg: fab production task; where production sets the username, hostname, port, and ssh identity.
As for rsync project, that should now have port setting ability, if not, you can always run local("rsync ...") as that is essentially what that contributed function does.
可以使用以下代码来读取配置(原始代码取自:http://markpasc.typepad.com/blog/2010/04/loading-ssh-config-settings-for-fabric.html):
One can use following code to read the config (original code taken from: http://markpasc.typepad.com/blog/2010/04/loading-ssh-config-settings-for-fabric.html):