运行Ansible剧本时ssh-rsa密钥错误

时间:2019-05-15 10:24:58

标签: ssh ansible key paramiko

我有以下剧本:

---
- name: Get Nokia Info
  hosts: LAB9ERIP008
  connection: local
  gather_facts: no

  tasks:
    - name: run show version command
      sros_command:
        commands: show version
      register: config

    - name: create backup of configuration
      copy:
        content: "{{config.stdout[0]}}"
        dest: "/home/dafe/scripts/ansible/backups/show_version_{{inventory_hostname}}.txt"

当我运行剧本时,出现以下错误:

[dafe@CETPMGIP001 ansible]$ ansible-playbook nokia.yml -i myhostsfile 

PLAY [Get Cisco Info] **************************************************************************************************************

TASK [run show version command] ****************************************************************************************************
fatal: [LAB9ERIP008]: FAILED! => {"msg": "paramiko: The authenticity of host '10.150.16.129' can't be established.\nThe ssh-rsa key fingerprint is fca0d4eb97414dc5b5a13fa552e5dd69."}
        to retry, use: --limit @/home/dafe/scripts/ansible/nokia.retry

PLAY RECAP *************************************************************************************************************************
LAB9ERIP008                : ok=0    changed=0    unreachable=0    failed=1  

我试图将var放入myhostsfile中。

ansible_ssh_private_key_file=/home/dafe/.ssh/known_hosts

但继续给出相同的错误。

如果我手动对主机执行ssh并添加密钥:

[dafe@CETPMGIP001 ansible]$ ssh dafernandes@10.150.16.129
The authenticity of host '10.150.16.129 (10.150.16.129)' can't be established.
RSA key fingerprint is SHA256:0YQYfLnRCQDZzpZ1+8ekW/Gks6mTxpI4xA56siaQUsM.
RSA key fingerprint is MD5:fc:a0:d4:eb:97:41:4d:c5:b5:a1:3f:a5:52:e5:dd:69.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '10.150.16.129' (RSA) to the list of known hosts.
TiMOS-C-16.0.R6 cpm/hops64 Nokia 7750 SR Copyright (c) 2000-2019 Nokia.
All rights reserved. All use subject to applicable license agreements.
Built on Wed Feb 27 14:42:05 PST 2019 by builder in /builds/c/160B/R6/panos/main

dafernandes@10.150.16.129's password: 

然后运行剧本不再犯错误:

[dafe@CETPMGIP001 ansible]$ ansible-playbook nokia.yml -i myhostsfile 

PLAY [Get Cisco Info] **************************************************************************************************************

TASK [run show version command] ****************************************************************************************************
ok: [LAB9ERIP008]

TASK [create backup of configuration] **********************************************************************************************
ok: [LAB9ERIP008]

PLAY RECAP *************************************************************************************************************************
LAB9ERIP008                : ok=2    changed=0    unreachable=0    failed=0   

我该如何解决?

谢谢。

大卫

1 个答案:

答案 0 :(得分:0)

ansible.cfg文件的[defaults]部分中,尝试设置密钥host_key_checking = false

这显然不那么安全。

由于SSH是Ansible用于与目标主机进行通信的主要机制,因此在尝试执行Ansible剧本之前 ,在您的环境中正确配置SSH至关重要。

在这种情况下,潜在的问题可能是与您要连接的SSH主机关联的SSH密钥已更改,并且不再与〜/ .ssh / known-hosts中的密钥匹配。可以在here中找到有关SSH主机密钥的更多信息。