Wednesday 19 October 2022

How to fix Ansible error "Failed to connect to the host via ssh: Unable to negotiate with 127.0.0.1"

On my Ubuntu 22.04 box I had a case where Packer was executing Ansible template and Gathering Facts task was failing with the following error:
 
...
amazon-ebs:
amazon-ebs: TASK [Gathering Facts] *********************************************************
==> amazon-ebs: failed to handshake
amazon-ebs: fatal: [default]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: Unable to negotiate with 127.0.0.1 port 37203: no matching host key type found. Their offer: ssh-rsa", "unreachable": true}
amazon-ebs:
...
 

The solution is to allow authentication with RSA keys by making sure the following lines are present in /etc/ssh/ssh_config:
 
PubkeyAcceptedAlgorithms ssh-rsa
HostkeyAlgorithms ssh-rsa


Resources:

 

No comments: