使用Fabric时连接到〜/.ssh/config中列出的主机 [英] Connecting to a host listed in ~/.ssh/config when using Fabric

查看:61
本文介绍了使用Fabric时连接到〜/.ssh/config中列出的主机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了 Fabric 遇到的问题识别我在~/.ssh/config中拥有的主机.

I'm having trouble with Fabric not recognizing hosts that I have in ~/.ssh/config.

我的fabfile.py如下:

from fabric.api import run, env

env.hosts = ['lulu']

def whoami():
    run('whoami')

运行$ fab whoami给出:

[lulu]奔跑:whoami

[lulu] run: whoami

致命错误:的名称查找失败 露露

Fatal error: Name lookup failed for lulu

名称lulu在我的~/.ssh/config中,如下所示:

The name lulu is in my ~/.ssh/config, like this:

Host lulu
     hostname 192.168.100.100
     port 2100
     IdentityFile ~/.ssh/lulu-key

解决这个问题的第一个想法是在/etc/hosts中添加类似lulu.lulu的东西(我在Mac上),但是随后我还必须将身份文件传递给Fabric-我宁愿保留我的身份验证(即~/.ssh/config)与我的部署(即fabfile.py)分开.

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).

此外,顺便说一句,如果您尝试连接到hosts文件中的主机,则fabric.contrib.projects.rsync_project似乎并没有认可hosts.env中的端口"(即,如果您使用hosts.env = [lulu:2100]来调用rsync_project似乎尝试连接到lulu:21).

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).

Fabric无法识别此lulu名称吗?

Is there a reason Fabric doesn't recognize this lulu name?

推荐答案

从1.4.0版开始,

Since version 1.4.0, Fabric uses your ssh config (partly). However, you need to explicitly enable it, with

env.use_ssh_config = True

靠近fabfile顶部的位置.完成此操作后,Fabric应该读取您的ssh配置(默认情况下是从~/.ssh/config或从env.ssh_config_path).

somewhere near the top of your fabfile. Once you do this, Fabric should read your ssh config (from ~/.ssh/config by default, or from env.ssh_config_path).

一个警告:如果您使用的版本低于1.5.4,则设置env.use_ssh_config但不存在配置文件时,将发生中止.在这种情况下,您可以使用以下解决方法:

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:

if env.ssh_config_path and os.path.isfile(os.path.expanduser(env.ssh_config_path)):
    env.use_ssh_config = True

这篇关于使用Fabric时连接到〜/.ssh/config中列出的主机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆