Bri*_*unt 83 python ssh fabric
我Fabric
无法识别我所拥有的主机~/.ssh/config
.
我的fabfile.py
情况如下:
from fabric.api import run, env
env.hosts = ['lulu']
def whoami():
run('whoami')
Run Code Online (Sandbox Code Playgroud)
跑步$ fab whoami
给出:
[lulu]跑:whoami
致命错误:lulu的名称查找失败
这个名字lulu
在我的~/.ssh/config
,就像这样:
Host lulu
hostname 192.168.100.100
port 2100
IdentityFile ~/.ssh/lulu-key
Run Code Online (Sandbox Code Playgroud)
我首先想到的解决,这是添加类似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
名字的原因?
rbp*_*rbp 144
从版本1.4.0开始,Fabric使用您的ssh配置(部分).但是,您需要使用显式启用它
env.use_ssh_config = True
Run Code Online (Sandbox Code Playgroud)
靠近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
Run Code Online (Sandbox Code Playgroud)