geerlingguy / internet-pi

Raspberry Pi config for all things Internet.
MIT License
4.15k stars 440 forks source link

Can't run 'ansible-playbook main.yml' on Pi itself [Permission denied (publickey,password)] #503

Closed adamtomajko closed 1 year ago

adamtomajko commented 1 year ago

I have done everything in documentation "README" and came to "ansible-playbook main.yml"

than i was given this response 👇🏻

pi@rpi1:~/internet-pi $ ansible-playbook main.yml

PLAY [Configure Internet Pi.] ***************************************************************************************

TASK [Gathering Facts] **********************************************************************************************
fatal: [10.111.10.11]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: pi@10.111.10.11: Permission denied (publickey,password).", "unreachable": true}

PLAY RECAP **********************************************************************************************************
10.111.10.11               : ok=0    changed=0    unreachable=1    failed=0    skipped=0    rescued=0    ignored=0   

I found similar issue here -> https://github.com/geerlingguy/internet-pi/issues/20

In inventory.ini, I change the line under [internet_pi] to read: localhost ansible_connection=local

but I was given different response as user in issue/20 response 👇🏻

pi@rpi1:~/internet-pi $ ansible-playbook main.yml

PLAY [Configure Internet Pi.] ***************************************************************************************

TASK [Gathering Facts] **********************************************************************************************
fatal: [localhost]: FAILED! => {"ansible_facts": {}, "changed": false, "failed_modules": {"ansible.legacy.setup": {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python3"}, "failed": true, "module_stderr": "sudo: a password is required\n", "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}}, "msg": "The following modules failed to execute: ansible.legacy.setup\n"}

PLAY RECAP **********************************************************************************************************
localhost                  : ok=0    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0   

Background of setup

Running Raspberry Pi 3 B+ (I know it is not recommended) eth0 static ip 10.111.10.11

ssh enabled as pi@rpi1.local and also pi@10.111.10.11 (I tried it from both)

in config.yml i change only

pihole_password: "mypasswd"
monitoring_grafana_admin_password: "mypasswd"
monitoring_ping_hosts: 

 - https://www.example.com/;example.com

and my objective is to run only Grafana so

pihole_enable: false

In beginning, I had issues with ansible-galaxy collection install -r requirements.yml

ansible-galaxy: command not found even after couple reboots nothing so I use pip3 install ansible

and copy whole ansible files to internet-pi

*side note I am complete beginner and I had to google even simple linux commands :D

adamtomajko commented 1 year ago

I was able to run it! 🙌🏻

and for everyone with the same issues here me workaround.

I save inventory.ini with inicial instruction (and commented localhost access)

# localhost ansible_connection=local
 10.111.10.11 ansible_user=pi

Reboot Pi and issue was same 👇🏻

pi@rpi1:~/internet-pi $ ansible-playbook main.yml

PLAY [Configure Internet Pi.] ***************************************************************************************

TASK [Gathering Facts] **********************************************************************************************
fatal: [10.111.10.11]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: pi@10.111.10.11: Permission denied (publickey,password).", "unreachable": true}

PLAY RECAP **********************************************************************************************************
10.111.10.11               : ok=0    changed=0    unreachable=1    failed=0    skipped=0    rescued=0    ignored=0   

then I try to use ssh password for it by ansible-playbook main.yml -k but was given this 👇🏻

SSH password: 

PLAY [Configure Internet Pi.] ***************************************************************************************

TASK [Gathering Facts] **********************************************************************************************
fatal: [localhost]: FAILED! => {"ansible_facts": {}, "changed": false, "failed_modules": {"ansible.legacy.setup": {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python3"}, "failed": true, "module_stderr": "sudo: a password is required\n", "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}}, "msg": "The following modules failed to execute: ansible.legacy.setup\n"}

PLAY RECAP **********************************************************************************************************
localhost                  : ok=0    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0   

then I install sshpass initially by apt-get install sshpass but was given 👇🏻

E: Could not open lock file /var/lib/dpkg/lock-frontend - open (13: Permission denied)
E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), are you root?

so I use sudo apt-get install sshpass succesfully!

Then I use ansible-playbook main.yml -kK

Type 2 times ssh password and everything worked like a charm. 🙌🏻