Ansible ping 不起作用

Ansible ping 不起作用

我在 Ubuntu 机器(18.04.2)中的 VM Workstation 15 Pro 中使用 Ansible 2.7.10,并尝试在 GNS3 中连接思科路由器(3700 软件(C3725-ADVIPSERVICESK9-M),版本 12.4(23))。

原始 ssh 正在从 Ubuntu 终端运行,但在尝试通过 ansible ping 模块进行 ping 时出现以下错误。

root@ubuntu:/etc/ansible# ansible Routers -m ping -u cisco -k -vvv
ansible 2.7.10
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/dist-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.15rc1 (default, Nov 12 2018, 14:31:15) [GCC 7.3.0]
Using /etc/ansible/ansible.cfg as config file
SSH password: 
/etc/ansible/hosts did not meet host_list requirements, check plugin documentation if this is unexpected
/etc/ansible/hosts did not meet script requirements, check plugin documentation if this is unexpected
Parsed /etc/ansible/hosts inventory source with ini plugin
META: ran handlers
<192.168.74.10> ESTABLISH SSH CONNECTION FOR USER: cisco
<192.168.74.10> SSH: EXEC sshpass -d9 ssh -C -o ControlMaster=no -o StrictHostKeyChecking=no -o User=cisco -o ConnectTimeout=10 192.168.74.10 '/bin/sh -c '"'"'echo ~cisco && sleep 0'"'"''
<192.168.74.10> (0, '\r\nLine has invalid autocommand "/bin/sh -c \'echo ~cisco && sleep 0\'"', '')
<192.168.74.10> ESTABLISH SSH CONNECTION FOR USER: cisco
<192.168.74.10> SSH: EXEC sshpass -d9 ssh -C -o ControlMaster=no -o StrictHostKeyChecking=no -o User=cisco -o ConnectTimeout=10 192.168.74.10 '/bin/sh -c '"'"'( umask 77 && mkdir -p "` echo Line has invalid autocommand "/bin/sh -c '"'"'"'"'"'"'"'"'echo ~cisco && sleep 0'"'"'"'"'"'"'"'"'"/.ansible/tmp/ansible-tmp-1557556461.94-275071590111448 `" && echo ansible-tmp-1557556461.94-275071590111448="` echo Line has invalid autocommand "/bin/sh -c '"'"'"'"'"'"'"'"'echo ~cisco && sleep 0'"'"'"'"'"'"'"'"'"/.ansible/tmp/ansible-tmp-1557556461.94-275071590111448 `" ) && sleep 0'"'"''
<192.168.74.10> (0, '\r\nLine has invalid autocommand "/bin/sh -c \'( umask 77 && mkdir -p "` echo Line has invalid autocommand "/bin/sh -c \'"\'"\'echo ~cisco && sleep 0\'"\'"\'"/.ansible/tmp/ansible-tmp-1557556461.94-275071590111448 `" && echo ansible-tmp-1557556461.94-275071590111448="` echo Line has invalid auto"', '')
Using module file /usr/lib/python2.7/dist-packages/ansible/modules/system/ping.py
<192.168.74.10> PUT /root/.ansible/tmp/ansible-local-82605nzIYYL/tmpRi045V TO "` echo Line has invalid auto"/AnsiballZ_ping.py
<192.168.74.10> SSH: EXEC sshpass -d9 scp -C -o ControlMaster=no -o StrictHostKeyChecking=no -o User=cisco -o ConnectTimeout=10 /root/.ansible/tmp/ansible-local-82605nzIYYL/tmpRi045V '[192.168.74.10]:'"'"'"` echo Line has invalid auto"/AnsiballZ_ping.py'"'"''
192.168.74.10 | FAILED! => {
    "msg": "failed to transfer file to /root/.ansible/tmp/ansible-local-82605nzIYYL/tmpRi045V \"` echo Line has invalid auto\"/AnsiballZ_ping.py:\n\nAdministratively disabled.\n"
}

请指教。

答案1

模块ping在 ansible 中,实际上并不像你从 shell 手动执行的那样 ping 主机。来自上面的文档链接:

这不是 ICMP ping,这只是一个需要远程节点上的 Python 的简单测试模块。

由于您的目标是网络设备,因此您会收到错误,因为 ansible 试图在使用 python 执行某些文件之前将其传输到设备,就像在“普通”主机上一样。 在您的例子中,设备文件系统在预期路径上是只读的或不可写的(这并不奇怪),ansible 会触发错误。

看看ios_pingnet_ping可能满足您需求的模块。

相关内容