Open mernamer opened 3 years ago
did you manage to solve the issue? i got the same..
ansible-playbook -i hosts main.yml
PLAY [local] *****
TASK [Gathering Facts] *** fatal: [localhost]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: root@localhost: Permission denied (publickey,password).", "unreachable": true}
PLAY RECAP *** localhost : ok=0 changed=0 unreachable=1 failed=0 skipped=0 rescued=0 ignored=0
sudo: unable to resolve host raspberrypi: Name or service not known
you need to have raspberrypi in your /etc/hosts file ;)
fatal: [localhost]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: root@localhost: Permission denied (publickey,password).", "unreachable": true}
This is not the same issue, here you try to do a ssh root@localhost
which is not allowed. you might want to add that user pub key to the root's authorized_keys.
getting same issue but it's pi@localhost. When I just try 'ssh pi@localhost' on the pi then it just asks for the password then typing in pi's password it logs in just fine. Do I need to include the password somewhere?
On a whim I just changed the top of the inventory file from localhost to the local IP address of the pi. TASK [Gathering Facts] ***** The authenticity of host '192.168.50.124 (192.168.50.124)' can't be established. ECDSA key fingerprint is SHA256:LN8AXEMaaXB2M4kS...... Are you sure you want to continue connecting (yes/no/[fingerprint])? yes fatal: [192.168.50.124]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: Warning: Permanently added '192.168.50.124' (ECDSA) to the list of known hosts.\r\npi@192.168.50.124: Permission denied (publickey,password).", "unreachable": true}
Why can I ssh just fine but the ansible playbook cannot reach it? What permission am I missing? Do I need to store the pi user's password somewhere?
pi@diasporapi:~/diaspora-pi $ ansible-playbook -i inventory install.yaml
PLAY [Install] *****
TASK [Gathering Facts] ***** fatal: [192.168.50.124]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: pi@192.168.50.124: Permission denied (publickey,password).", "unreachable": true}
PLAY RECAP ***** 192.168.50.124 : ok=0 changed=0 unreachable=1 failed=0 skipped=0 rescued=0 ignored=0
pi@diasporapi:~/diaspora-pi $ ssh pi@192.168.50.124 pi@192.168.50.124's password: Linux diasporapi 5.15.61-v7+ #1579 SMP Fri Aug 26 11:10:59 BST 2022 armv7l
The programs included with the Debian GNU/Linux system are free software; the exact distribution terms for each program are described in the individual files in /usr/share/doc/*/copyright.
Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent permitted by applicable law. Last login: Mon Mar 13 11:49:45 2023 from ::1 pi@diasporapi:~ $ <--- sitting at the SSH'ed prompt just fine.
Found this link: https://stackoverflow.com/questions/50855206/unreachable-error-while-running-an-ansible-playbook
Followed the steps to call ssh-keygen -t rsa while in the pi user's home folder. Created that authorized_keys file right in the /home/pi/.ssh folder. Calling that ansible ping command returned the SUCCESS message as shown.
Now getting good results!
sudo: unable to resolve host raspberrypi: Name or service not known
you need to have raspberrypi in your /etc/hosts file ;)
fatal: [localhost]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: root@localhost: Permission denied (publickey,password).", "unreachable": true}
This is not the same issue, here you try to do a
ssh root@localhost
which is not allowed. you might want to add that user pub key to the root's authorized_keys.
sounds like you had the right answer here but need more steps for us newbies to ssh keygen. :)
For what it's worth, I also had this issue:
fatal: [192.168.50.124]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: pi@192.168.50.124: Permission denied (publickey,password).", "unreachable": true}
And this fixed it, in a couple of steps:
The error message indicates that the public key file ~/.ssh/id_rsa.pub
does not exist. This typically means that an SSH key pair has not been generated yet. Here are the steps to generate an SSH key pair and add the public key to the authorized_keys
file:
Generate an SSH Key Pair: Run the following command to generate a new SSH key pair. Accept the default file location by pressing Enter when prompted.
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
This will create the key pair in the default location (~/.ssh/id_rsa
and ~/.ssh/id_rsa.pub
).
Add the Public Key to authorized_keys
:
Once the key pair is generated, add the public key to the authorized_keys
file.
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys
I keep getting this:
pi@raspberrypi:~/diaspora-pi $ sudo ansible-playbook -i inventory install.yaml sudo: unable to resolve host raspberrypi: Name or service not known [...] fatal: [localhost]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: root@localhost: Permission denied (publickey,password).", "unreachable": true} to retry, use: --limit @/home/pi/diaspora-pi/install.retry
No clues whatsoever. I can't resolve my own local host?