使用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的名称查找失败
名称lulu
在my中~/.ssh/config
,如下所示:
Host lulu
hostname 192.168.100.100
port 2100
IdentityFile ~/.ssh/lulu-key
我首先想到的解决,这是添加类似lulu.lulu
以/etc/hosts
(我在Mac),但后来我也必须通过在身份文件面料-
我宁愿让我的认证(即~/.ssh/config
)从我的部署分开(即fabfile.py
)。
同样,顺便说一句,如果您尝试连接到hosts文件中的主机,fabric.contrib.projects.rsync_project
似乎并不会在中确认“端口”
hosts.env
(即,如果您使用hosts.env =
[lulu:2100]
调用rsync_project
似乎尝试连接到lulu:21
)。
Fabric是否无法识别此lulu
名称?
-
从1.4.0版开始,Fabric使用ssh配置(部分)。但是,您需要使用以下命令显式启用它
env.use_ssh_config = True
fabfile顶部附近的某处。完成此操作后,Fabric应该读取您的ssh配置(
~/.ssh/config
默认情况下为,或者为env.ssh_config_path
)。一个警告:如果您使用的版本低于1.5.4,则如果
env.use_ssh_config
设置为中止但没有配置文件,则会中止操作。在这种情况下,您可以使用类似的解决方法:if env.ssh_config_path and os.path.isfile(os.path.expanduser(env.ssh_config_path)): env.use_ssh_config = True