Failed to connect to the host via ssh: Host key verification failed Failed to connect to the host via ssh: Host key verification failed jenkins jenkins

Failed to connect to the host via ssh: Host key verification failed


Your known_hosts file in the jenkins-ansible host already has an entry for the host centos-slave-02. Now that the centos-slave-02 host's identity has changed, a new entry needs to be added. But the existing entry in the file is throwing this warning.

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:2Matching host key in /var/jenkins_home/.ssh/known_hosts:5

You can either manually edit the /var/jenkins_home/.ssh/known_hosts file to remove the key for this centos-slave-02 host or run the below command,

ssh-keygen -R centos-slave-02

The workaround with ansible would be to add this line in ansible.cfg under [defaults] section,

[defaults]host_key_checking = False

This will disable HostKeyChecking when making SSH connections.


Make sure you don't use sudo in your jenkin build Exec command.