我无法在 Ansible 2.1 中运行ios_command模块来在我的思科路由器上执行命令。
我编写了一本用于在思科路由器上测试ios_command模块的手册。
以下是我写的剧本
---
- hosts: router2
tasks:
- ios_command:
username: cisco
password: cisco
# host: router2.3node.example.com
commands:
- show version
register: output
- debug: msg="Hello World! {{ output.stdout }}"
但剧本失败,并显示以下消息:
fatal: [router2.3node.example.com]: UNREACHABLE! => {"changed": false,
"msg": "Failed to connect to the host via ssh.", "unreachable": true}
和价值unreachable=1
还可以在调试模式下运行时找到输出:
TASK [setup]
*******************************************************************
Using module file /home/cisco/ansible_dev/ansible/lib/ansible/modules
/core/system/setup.py
<router2.3node.example.com> ESTABLISH SSH CONNECTION FOR USER: None
<router2.3node.example.com> SSH: EXEC ssh -C -q -o ControlMaster=auto
-o ControlPersist=60s -o KbdInteractiveAuthentication=no -o
PreferredAuthentications=gssapi-with-mic,gssapi-
keyex,hostbased,publickey -o PasswordAuthentication=no -o
ConnectTimeout=10 -o ControlPath=/home/cisco/.ansible/cp/ansible-
ssh-%h-%p-%r router2.3node.example.com '/bin/sh -c '"'"'( umask 77 &&
mkdir -p "` echo $HOME/.ansible/tmp/ansible-
tmp-1464109982.9-18150317646623 `" && echo ansible-
tmp-1464109982.9-18150317646623="` echo $HOME/.ansible/tmp/ansible-
tmp-1464109982.9-18150317646623 `" ) && sleep 0'"'"''
fatal: [router2.3node.example.com]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh.", "unreachable": true}
如果有人尝试过相同的方法并解决了这个问题,请告诉我。
请尝试在剧本中添加以下两行:
gather_facts:否 连接:本地