我是 Ansible 的新手,我的目标是使用此工具通过 SSH 接口配置 Moxa 交换机。我能够从我的 Ubuntu PC 通过 SSH 连接,没有任何问题:
[email protected]'s password:
Please change default password in consideration of higher security level.
MOXA EDR-810 Series V5.12.9 build 22052312.
--------------------------------------------------------------------------------
Firewall/VPN Router 04106# quit
Firewall/VPN Router 04106# Connection to 192.168.127.254 closed.
然而在我发送这样的 ping 消息之后
ansible all -m ping
我收到此错误消息
ansible 2.9.6
config file = /etc/ansible/ansible.cfg
configured module search path = ['/home/rodrigo/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3/dist-packages/ansible
executable location = /usr/bin/ansible
python version = 3.8.10 (default, Jun 22 2022, 20:18:18) [GCC 9.4.0]
Using /etc/ansible/ansible.cfg as config file
setting up inventory plugins
host_list declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
script declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
auto declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
Parsed /etc/ansible/hosts inventory source with ini plugin
Loading callback plugin minimal of type stdout, v2.0 from /usr/lib/python3/dist-packages/ansible/plugins/callback/minimal.py
META: ran handlers
<192.168.127.254> ESTABLISH SSH CONNECTION FOR USER: admin
<192.168.127.254> SSH: EXEC sshpass -d11 ssh -vvv -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o 'User="admin"' -o ConnectTimeout=10 -o ControlPath=/home/rodrigo/.ansible/cp/f1d5153c55 192.168.127.254 '/bin/sh -c '"'"'echo ~admin && sleep 0'"'"''
<192.168.127.254> (255, b'', b'OpenSSH_8.2p1 Ubuntu-4ubuntu0.2, OpenSSL 1.1.1f 31 Mar 2020\r\n
debug1: Reading configuration data /etc/ssh/ssh_config\r\n
debug1: /etc/ssh/ssh_config line 19: include /etc/ssh/ssh_config.d/*.conf matched no files\r\n
debug1: /etc/ssh/ssh_config line 21: Applying options for *\r\n
debug2: resolve_canonicalize: hostname 192.168.127.254 is address\r\n
debug1: auto-mux: Trying existing master\r\ndebug2: fd 3 setting O_NONBLOCK\r\n
debug2: mux_client_hello_exchange: master version 4\r\n
debug3: mux_client_forwards: request forwardings: 0 local, 0 remote\r\n
debug3: mux_client_request_session: entering\r\n
debug3: mux_client_request_alive: entering\r\n
debug3: mux_client_request_alive: done pid = 1118\r\n
debug3: mux_client_request_session: session request sent\r\n
debug3: mux_client_read_packet: read header failed: Broken pipe\r\n
debug2: Control master terminated unexpectedly\r\n')
192.168.127.254 | UNREACHABLE! => {
"changed": false,
"msg": "Failed to connect to the host via ssh: OpenSSH_8.2p1 Ubuntu-4ubuntu0.2, OpenSSL 1.1.1f 31 Mar 2020\r\n
debug1: Reading configuration data /etc/ssh/ssh_config\r\n
debug1: /etc/ssh/ssh_config line 19: include /etc/ssh/ssh_config.d/*.conf matched no files\r\n
debug1: /etc/ssh/ssh_config line 21: Applying options for *\r\n
debug2: resolve_canonicalize: hostname 192.168.127.254 is address\r\n
debug1: auto-mux: Trying existing master\r\n
debug2: fd 3 setting O_NONBLOCK\r\ndebug2: mux_client_hello_exchange: master version 4\r\n
debug3: mux_client_forwards: request forwardings: 0 local, 0 remote\r\n
debug3: mux_client_request_session: entering\r\n
debug3: mux_client_request_alive: entering\r\n
debug3: mux_client_request_alive: done pid = 1118\r\n
debug3: mux_client_request_session: session request sent\r\n
debug3: mux_client_read_packet: read header failed: Broken pipe\r\n
debug2: Control master terminated unexpectedly",
"unreachable": true
}
有什么想法可以解决这个问题吗?
所以:Ubuntu Server 20
问候
答案1
根据提供的输出,您似乎尝试与交换机建立 SSH 连接。此类设备可能不具备 Python 脚本的所有功能。
因为ping
模块 – 尝试连接主机,验证可用的 Python,并在成功时返回 pong它 ”不是 ICMP ping,...只是一个需要远程节点上的 Python 的简单测试模块“。
此外,为了做到这一点,Ansible 会尝试在远程节点上运行/bin/sh -c
,这在您的目标上也可能无法实现。
换句话说,Ansible 不仅可以通过 SSH 连接到目标节点,还可以执行在您的情况下可能会失败的其他任务。
您可能需要使用 MOXA EDR-810 系列防火墙 VPN 路由器的特定自定义或社区模块、利用 REST API 接口或使用不推荐的raw
模块 – 执行低级且肮脏的命令
更多问答