通过SSH向Cisco IOS发送“身份验证失败”消息

时间:2016-05-13 10:21:06

标签: ssh ansible cisco

这是一个非常简单的ansible案例,让我很烦恼。

这是ansible.cfg的内容:

[defaults]
transport = paramiko
hostfile = ./hosts
host_key_checking = False
timeout = 5

主机内容,所有用户名为“cisco”,密码为“cisco”

[routers]
R1
R2
R3
...

主机变量文件(R1),类似于R2,R3,......,IP地址不同:

---
ansible_ssh_host: 10.10.10.1
ansible_ssh_user: cisco
ansible_ssh_pass: cisco

我可以通过linux成功SSH到这些路由器,但是当我使用ansible时,它导致“身份验证失败”:

fatal: [R1] => {'msg': 'FAILED: Authentication failed.', 'failed': True}
fatal: [R2] => {'msg': 'FAILED: Authentication failed.', 'failed': True}
...

我使用一行ansible命令测试了连接性,即使我手动输入用户名和密码仍会出现错误,例如:

> ansible routers -m raw
R1 | FAILED => FAILED: Authentication failed.
R2 | FAILED => FAILED: Authentication failed.    

> ansible routers -u cisco -m raw
R1 | FAILED => FAILED: Authentication failed.
R2 | FAILED => FAILED: Authentication failed.

> ansible routers -u cisco -m raw -k
SSH password:
R1 | FAILED => FAILED: Authentication failed.
R2 | FAILED => FAILED: Authentication failed.

我该如何解决这个问题?帮助将不胜感激。

1 个答案:

答案 0 :(得分:0)

Python解释器connect() for paramiko connections可以像这样使用:

  

connect(hostname, port=22, username=None, password=None, pkey=None, key_filename=None, timeout=None, allow_agent=True, look_for_keys=True, compress=False, sock=None, gss_auth=False, gss_kex=False, gss_deleg_creds=True, gss_host=None, banner_timeout=None, auth_timeout=None)

     

[...]

     

look_for_keys (bool) - 设置为False以禁用在~/.ssh/

中搜索可发现的私钥文件