本文介绍了Ansible 停止通过 ssh 连接到主机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
一个多月以来,我一直在运行以下命令:
For over a month I've been running the following command:
ansible-playbook -vvvvi host_test rhel-tests.yml
通过 SSH 连接并在主机上成功运行测试,没有任何问题.但截至最近几天,我在运行时收到以下信息:
Which connected via SSH and ran tests on a host successfully without any problems.But as of the last couple days, I've received the following when running:
fatal: [10.2.16.2]: UNREACHABLE! => {
"changed": false,
"unreachable": true
}
MSG:
Failed to connect to the host via ssh: OpenSSH_7.6p1, LibreSSL 2.6.2
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 48: Applying options for *
debug1: auto-mux: Trying existing master
debug2: fd 3 setting O_NONBLOCK
debug2: mux_client_hello_exchange: master version 4
debug3: mux_client_forwards: request forwardings: 0 local, 0 remote
debug3: mux_client_request_session: entering
debug3: mux_client_request_alive: entering
debug3: mux_client_request_alive: done pid = 35742
debug3: mux_client_request_session: session request sent
debug1: mux_client_request_session: master session id: 2
debug3: mux_client_read_packet: read header failed: Broken pipe
debug2: Control master terminated unexpectedly
Shared connection to 10.2.16.2 closed.
即使我可以从我正在运行的主机上建立从 bash 到 10.2.16.2 的正常 SSH 连接也很好.
Even though I can establish a normal SSH connection from bash to 10.2.16.2 just fine from the host I'm running.
host_test
的内容如下:
[rhel]
10.2.16.2 node_type=xxx
[rhel:vars]
ansible_become=yes
ansible_become_method=su
ansible_become_user=root
ansible_connection=ssh
ansible_user=yyy
node_name=""
[cisco]
[cisco:vars]
node_name=""
[curtiss-wright]
[zzz]
[other]
[nmap:children]
rhel
cisco
curtiss-wright
other
zzz
[password-test]
这是我的ansible.cfg
:
[defaults]
ask_vault_pass = True
filter_plugins = filter_plugins
host_key_checking = False
retry_files_enabled = False
inventory = hosts
stdout_callback = debug
[paramiko_connection]
record_host_keys=False
[ssh_connection]
ssh_args = -o LogLevel=QUIET -o ControlMaster=auto -o ControlPersist=2m -o UserKnownHostsFile=/dev/null
scp_if_ssh = True
我的想法
- 目标上的配置不断发生变化,因此可能在 ssh 中配置了某些内容以某种方式限制连接.
- 正在将测试添加到
rhel-tests.yml
,因此现在可能会触发某种以前没有的超时.我已经尝试将rhel7的版本恢复到大约一个月前,但命令仍然失败,所以我认为这不太可能是原因. - 我使用的是通过 brew 安装的 ansible 2.5.4 版.我尝试更新到 Ansible 2.6.2,但似乎没有任何效果.
- 我尝试了网上找到的其他几个建议,包括使用
paramiko_ssh
连接类型,但也失败了. - 我可以运行
ansible -i hosts_test -m ping 10.2.16.2
并恢复正常 - 这个问题似乎很接近我的问题,但没有
rhel-tests.yml
中重启或关闭的行. - Configuration changes are happening constantly on the target, so it's possible something was configured in ssh to limit connections in some way.
- Tests are being added to
rhel-tests.yml
, so it's possible some sort of timeout is now being triggered that wasn't before. I've tried reverting back the version of rhel7 to about a month back, and the command still fails, so I believe that this is not likely to be the cause. - I'm using ansible version 2.5.4 installed via brew. I've tried updating to Ansible 2.6.2, but that seems to have done nothing.
- I've tried several other suggestions found online, including using the
paramiko_ssh
connection type, which also fails. - I can run
ansible -i hosts_test -m ping 10.2.16.2
and get a pong back - This question seems pretty close to my issue, but there aren't any lines in
rhel-tests.yml
that reboot or shutdown.
My thoughts
是什么导致我的剧本失败,我该如何解决?
推荐答案
由于您的游戏输出不足,连接可能会中断.
The connection may be dropping due to the lack of output from your play.
将以下内容添加到 ansible.cfg
中的 ssh_args
:
Add the following to your ssh_args
in ansible.cfg
:
-o ServerAliveInterval=50
这篇关于Ansible 停止通过 ssh 连接到主机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!