【问题标题】:Failed to connect to the host via ssh: Host key verification failedssh连接主机失败:主机密钥验证失败
【发布时间】:2020-07-15 03:54:27
【问题描述】:

我在执行 Jenkins 的 ansible-playbook 表单时遇到问题,

喜欢:

PLAY [centos-slave-02] *********************************************************



TASK [Gathering Facts] *********************************************************

fatal: [centos-slave-02]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: Host key verification failed.", "unreachable": true}

PLAY RECAP *********************************************************************

centos-slave-02            : ok=0    changed=0    unreachable=1    failed=0    skipped=0    rescued=0    ignored=0   

但我能够得到乒乓响应,并且每次都要求

Matching host key in /var/jenkins_home/.ssh/known_hosts:5  :
jenkins@c11582cb5024:~/jenkins-ansible$ ansible -i hosts -m ping centos-slave-02

Warning: the ECDSA host key for 'centos-slave-02' differs from the key for the IP address '172.19.0.3'

Offending key for IP in /var/jenkins_home/.ssh/known_hosts:2

Matching host key in /var/jenkins_home/.ssh/known_hosts:5

Are you sure you want to continue connecting (yes/no)? yes

centos-slave-02 | SUCCESS => {

    "ansible_facts": {

        "discovered_interpreter_python": "/usr/bin/python"

    },

    "changed": false,

    "ping": "pong"

}

谁能解决这个问题!在此先感谢。

【问题讨论】:

    标签: jenkins ssh ansible centos ssh-keys


    【解决方案1】:

    jenkins-ansible 主机中的 known_hosts 文件已经有主机 centos-slave-02 的条目。现在centos-slave-02 主机的身份已更改,需要添加一个新条目。但是文件中的现有条目正在引发此警告。

    Warning: the ECDSA host key for 'centos-slave-02' differs from the key for the IP address '172.19.0.3'
    
    Offending key for IP in /var/jenkins_home/.ssh/known_hosts:2
    
    Matching host key in /var/jenkins_home/.ssh/known_hosts:5
    

    您可以手动编辑/var/jenkins_home/.ssh/known_hosts 文件以删除此centos-slave-02 主机的密钥或运行以下命令,

    ssh-keygen -R centos-slave-02
    

    使用 ansible 的解决方法是将此行添加到 ansible.cfg 下的 [defaults] 部分,

    [defaults]
    host_key_checking = False
    

    这将在建立 SSH 连接时禁用 HostKeyChecking

    【讨论】:

    • 请记住,禁用 HostKeyChecking 是非常糟糕的做法。最正确的做法是设置 SSH 用户/主机证书。
    【解决方案2】:

    确保不要在 jenkin build Exec 命令中使用 sudo。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-10-21
      • 2018-04-06
      • 2021-07-03
      • 2021-12-25
      • 2013-02-16
      • 1970-01-01
      • 2019-12-08
      • 2017-09-10
      相关资源
      最近更新 更多