gpt4 book ai didi

ssh - Ansible 通过堡垒服务器 SSH 错误

转载 作者:行者123 更新时间:2023-12-02 14:33:24 39 4
gpt4 key购买 nike

遵循本指南(和其他)running-ansible-through-ssh-bastion-host .
我设置了 ssh.cfg 文件以允许连接到多个堡垒后面的主机。

代理 -> 实用程序 -> 监视器 -> 更多

我可以连接到 util 服务器:
[self@home]$ ssh -F ssh.cfg util
...
[self@util]$

和监控服务器:
[self@home]$ ssh -F ssh.cfg monitor
...
[self@monitor]$

ssh.conf:

Host *
ServerAliveInterval 60
ControlMaster auto
ControlPath ~/.ssh/mux-%r@%h:%p
ControlPersist 15m

Host proxy
HostName proxy01.com
ForwardAgent yes

Host util
HostName util01.priv
ProxyCommand ssh -W %h:%p proxy

Host monitor
HostName mon01.priv
ProxyCommand ssh -W %h:%p util

ansible库存文件:
[bastion]
proxy

[utility]
util
monitor

ansible.cfg:
[ssh_connection]
ssh_args = -F ./ssh.cfg -o ControlMaster=auto -o ControlPersist=15m
control_path = ~/.ssh/ansible-%%r@%%h:%%p

当我执行任何 ansible 命令时,它们似乎可以毫无问题地命中代理主机,但无法连接到 util 主机和监视器主机。
> ansible all -a "/bin/echo hello"
util | UNREACHABLE! => {
"changed": false,
"msg": "SSH Error: data could not be sent to the remote host. Make sure this host can be reached over ssh",
"unreachable": true
}
proxy | SUCCESS | rc=0 >>
hello

monitor | UNREACHABLE! => {
"changed": false,
"msg": "Failed to connect to the host via ssh.",
"unreachable": true
}

额外的:
在进行了一些黑客攻击之后,我对监视器主机进行了 key 处理,发现 ansible 可以连接到代理和监视器,但是在 util 主机上失败了……这非常奇怪,因为它必须通过 util主机打显示器。
util | UNREACHABLE! => {
"changed": false,
"msg": "SSH Error: data could not be sent to the remote host. Make sure this host can be reached over ssh",
"unreachable": true
}
proxy | SUCCESS | rc=0 >>
hello
monitor | SUCCESS | rc=0 >>
hello

最佳答案

在尝试了不同的指南之后,这个解决方案可以让我在没有目录 ssh 但通过代理/堡垒的服务器上使用 ansible。

这是我的 ~/.ssh/config 文件:

Host *
ServerAliveInterval 60
StrictHostKeyChecking no
UserKnownHostsFile /dev/null
ForwardAgent yes

####### Access to the Private Subnet Server through Proxy/bastion ########

Host proxy-server
HostName x.x.x.x
ForwardAgent yes

Host private-server
HostName y.y.y.y
ProxyCommand ssh -q proxy-server nc -q0 %h %p

希望对您有所帮助。

关于ssh - Ansible 通过堡垒服务器 SSH 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37892392/

39 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com