jenkins - 无法通过 ssh 连接到主机 : Host key verification failed

标签 jenkins ssh ansible centos ssh-keys

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

喜欢:

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-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 主机的 key 或运行以下命令,

ssh-keygen -R centos-slave-02

ansible 的解决方法是在 [defaults] 部分下的 ansible.cfg 中添加这一行,

[defaults]
host_key_checking = False

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

关于jenkins - 无法通过 ssh 连接到主机 : Host key verification failed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61004090/

相关文章:

python - 如何在Jenkins构建python中运行nose2测试

php - php composer无法在public_html文件夹中访问

eclipse - 如何在 Eclipse 中使用 ssh 隧道设置颠覆?

linux - 如何使用ssh heredoc在bash中删除多个文件?

amazon-web-services - ec2_metric_alarm ansible 模块中的警报 Action 定义

authentication - 在具有域用户的 Windows 上使用 Ansible

macos - 如何在 Mac 上完全卸载 Jenkins

continuous-integration - jenkins - 重启后混合构建历史

git - Jenkins - 如果开始新的构建,则中止正在运行的构建

mysql - Vagrant、Ansible 和 MySql : ERROR! 在任务中未检测到任何操作。这通常表示模块名称拼写错误或模块路径不正确