无法使用Ansible 2.3.1.0连接到Cisco路由器
直接从linux ssh cisco@172.1.1.2工作
但是ansible -m ping都没有。 也许很清楚这个输出可能存在什么问题:
[osboxes@osboxes ~]$ ansible -m ping servers -vvv
Using /etc/ansible/ansible.cfg as config file
META: ran handlers
Using module file /usr/lib/python2.7/site-packages/ansible/modules/system/ping.py
<172.1.1.2> ESTABLISH SSH CONNECTION FOR USER: cisco
<172.1.1.2> SSH: EXEC sshpass -d12 ssh -C -o ControlMaster=auto -o ControlPersist=60s -o User=cisco -o ConnectTimeout=10 -o ControlPath=/home/osboxes/.ansible/cp/1ed8487ad4 172.1.1.2 '/bin/sh -c '"'"'echo ~ && sleep 0'"'"''
<172.1.1.2> (0, '\r\nLine has invalid autocommand "/bin/sh -c \'echo ~ && sleep 0\'"', '')
<172.1.1.2> ESTABLISH SSH CONNECTION FOR USER: cisco
<172.1.1.2> SSH: EXEC sshpass -d12 ssh -C -o ControlMaster=auto -o ControlPersist=60s -o User=cisco -o ConnectTimeout=10 -o ControlPath=/home/osboxes/.ansible/cp/1ed8487ad4 172.1.1.2 '/bin/sh -c '"'"'( umask 77 && mkdir -p "` echo Line has invalid autocommand "/bin/sh -c '"'"'"'"'"'"'"'"'echo ~ && sleep 0'"'"'"'"'"'"'"'"'"/.ansible/tmp/ansible-tmp-1499178341.35-260752414357590 `" && echo ansible-tmp-1499178341.35-260752414357590="` echo Line has invalid autocommand "/bin/sh -c '"'"'"'"'"'"'"'"'echo ~ && sleep 0'"'"'"'"'"'"'"'"'"/.ansible/tmp/ansible-tmp-1499178341.35-260752414357590 `" ) && sleep 0'"'"''
<172.1.1.2> (0, '\r\nLine has invalid autocommand "/bin/sh -c \'( umask 77 && mkdir -p "` echo Line has invalid autocommand "/bin/sh -c \'"\'"\'echo ~ && sleep 0\'"\'"\'"/.ansible/tmp/ansible-tmp-1499178341.35-260752414357590 `" && echo ansible-tmp-1499178341.35-260752414357590="` echo Line has invalid autocomma"', 'muxclient: master hello exchange failed\r\n')
<172.1.1.2> PUT /tmp/tmpacZGSy TO "` echo Line has invalid autocomma"/ping.py
<172.1.1.2> SSH: EXEC sshpass -d12 sftp -o BatchMode=no -b - -C -o ControlMaster=auto -o ControlPersist=60s -o User=cisco -o ConnectTimeout=10 -o ControlPath=/home/osboxes/.ansible/cp/1ed8487ad4 '[172.1.1.2]'
<172.1.1.2> (255, '', 'Connection closed\r\n')
172.1.1.2 | UNREACHABLE! => {
"changed": false,
"msg": "Failed to connect to the host via ssh: Connection closed\r\n",
"unreachable": true
感谢任何提示。
答案 0 :(得分:0)
看起来您正在连接到Cisco设备。由于IOS没有提供/bin/sh
命令,因此您无法使用ansible的ping
模块(或任何其他标准模块)。< / p>
然而,您可以尝试使用raw
module执行某些操作,这允许在不通过模块子系统的情况下发送命令。但是,当涉及到思科设备时,似乎有some bugs与该模块相关,因此您可能需要更新到最近的安塞版本。
答案 1 :(得分:0)
尝试添加:
ansible_connection = local
到库存文件中的[all:vars]
或[servers:var]
:
/[path]/ansible/hosts
如果需要,您还可以添加:
ansible_ssh_pass=some_password
ansible_ssh_user=username
到库存文件