Ansible 无法与 SSH 连接(横幅交换)

Ati*_*tik 6 ssh ansible

如果问题不清楚和/或如果我没有问我应该在哪里,请提前抱歉。

我在通过 SSH 连接到带有 ansible 的主机时遇到问题。几天前它起作用了,但几天来我一直有相同的消息错误:

        camille@ubuntu:~$ ansible all  -m ping -u remote
192.xxx.xxx.xxx | UNREACHABLE! => {
        "changed": false, 
        "msg": "Failed to connect to the host via ssh: Connection timed out during banner exchange\r\n", 
        "unreachable": true
    }
Run Code Online (Sandbox Code Playgroud)

SSH 连接(没有ansible)运行良好,所以我不太明白这个问题。我在 Ubuntu 16.04 VM 上运行 Ansible,我想访问的主机是 CentOS 7 VM。

我的主机文件如下:

[test]    
192.xxx.xxx.xxx ansible_ssh_user=remote ansible_ssh_pass=password ansible_sudo_pass='password' #VM CentOS
Run Code Online (Sandbox Code Playgroud)

我尝试了此处解释的解决方案但没有解决问题。

编辑 1:在尝试 Ripper Tops 解决方案并测试其他一些东西后,我的库存现在看起来像这样:

[test]
192.xxx.xxx.xxx ansible_connection=ssh ansible_user=remote ansible_password='password'

[test:vars]
proxy=my_proxy:8080
Run Code Online (Sandbox Code Playgroud)

我也尝试将超时增加到 25,但我仍然遇到同样的问题。

编辑2

更改我的 ansible.cfg 文件后,错误消息已更改:

192.xxx.xxx.xxx | UNREACHABLE! => {
    "changed": false, 
    "msg": "SSH Error: data could not be sent to remote host \"192.xxx.xxx.xxx\". Make sure this host can be reached over ssh", 
    "unreachable": true }
Run Code Online (Sandbox Code Playgroud)

我再次测试 ssh 连接,它仍然运行良好。

我的配置文件现在是:

[defaults]

timeout = 25
host_key_checking = False 
roles_path = roles/
gathering = smart 

[ssh_connection]
ssh_args = -o 
ControlMaster=auto -o 
ControlPersist=600s 
control_path = %(directory)s/%%h-%%r 
pipelining = True
Run Code Online (Sandbox Code Playgroud)

你有什么线索吗?

Rip*_*ops 5

尝试使用ansible_user替代ansible_ssh_useransible_password替代ansible_ssh_pass。这取决于你的ansible版本。此外,您可能需要在清单文件中的部分[group:vars]之后放置[group]

有一种简单的方法可以检查差异

ansible 192.168.15.29 -i your_hosts_file -m ping -e "ansible_ssh_user=remote ansible_ssh_pass=password"

或者

ansible 192.168.15.29 -i your_hosts_file -m ping -e "ansible_user=remote ansible_password=password"


Ati*_*tik 1

我终于解决了我的问题!:D

  • 我应用了 Ripper Tops 的建议(再次感谢):更改 ansible.cfg (参见第一条消息)

  • 我将主机文件更改为以下内容:

    [测试] 192.xxx.xxx.xxx ansible_user=远程 ansible_password=remote_password ansible_ssh_user=远程 ansible_ssh_pass=remote_password

    [测试:变量] proxy=my_proxy:8080

  • 我使用 -c paramiko 选项 ping 我的主机

再次感谢 Ripper Tops 的时间和帮助:)