I am trying to run simple playbook for remote host(webserver1).
playbook
-
name: "This is service play"
hosts: webserver1
tasks:
-
name: "start apache2 service"
service:
name: apache2
state: started #stopped
Getting below error –
root@kubemaster:/etc/ansible/playbook/modules/service# ansible-playbook apache2.yml
[WARNING]: * Failed to parse /etc/ansible/inventory/inventory.txt with ini plugin: /etc/ansible/inventory/inventory.txt:12: Section [all_servers:children] includes
undefined group: sql_servers
[WARNING]: Unable to parse /etc/ansible/inventory/inventory.txt as an inventory source
[WARNING]: No inventory was parsed, only implicit localhost is available
PLAY [This is service play] *****************************************************************************************************************************************
TASK [Gathering Facts] **********************************************************************************************************************************************
fatal: [webserver1]: UNREACHABLE! => {"changed": false, "msg": "Invalid/incorrect password: Permission denied, please try again.", "unreachable": true}
PLAY RECAP **********************************************************************************************************************************************************
webserver1 : ok=0 changed=0 unreachable=1 failed=0 skipped=0 rescued=0 ignored=0
My inventory file –
root@kubemaster:/etc/ansible/playbook/modules/service# cat ../../../inventory/inventory.txt
webserver1 ansible_host=192.168.1.12 ansible_ssh_pass=sneha ansible_connection=ssh ansible_port=22 ansible_user=root
sqlserver1 ansible_host=192.168.1.11 ansible_ssh_pass=sneha ansible_connection=ssh ansible_port=22 ansible_user=ahens
[web_servers]
websever1
[sql_server]
sqlserver1
[all_servers:children]
web_servers
sql_servers
I tried –
-
SSH access for the root user, editing the
/etc/ssh/sshd_config
file and change the **PermitRootLogin
**andPasswordAuthentication
option toyes
and restarted the SSH service on remote host. -
Checked the firewall rules – They are inactive on remote host. (Also tried to active the firewall and allow ssh service.)
-
Tried connecting to the remote host manually using SSH to verify that the credentials are correct. Credentials are correct but can’t login to remote host using ssh with root. (Default username is ahens and I can login through ssh without root.)
Root login
root@kubemaster:~# ssh [email protected] [email protected]'s password: Permission denied, please try again. [email protected]'s password: Permission denied, please try again.
ahens login
root@kubemaster:~# ssh [email protected] [email protected]'s password: Welcome to Ubuntu 22.04.2 LTS (GNU/Linux 5.15.0-69-generic x86_64) * Documentation: https://help.ubuntu.com * Management: https://landscape.canonical.com * Support: https://ubuntu.com/advantage System information as of Sun Apr 2 03:30:24 PM UTC 2023 System load: 0.1884765625 Usage of /: 69.6% of 8.02GB Memory usage: 18% Swap usage: 0% Processes: 133 Users logged in: 1 IPv4 address for docker0: 172.17.0.1 IPv4 address for enp0s3: 192.168.1.12 IPv6 address for enp0s3: 3ffe:501:ffff:100:a00:27ff:fe28:5a6e * Strictly confined Kubernetes makes edge and IoT secure. Learn how MicroK8s just raised the bar for easy, resilient and secure K8s cluster deployment. https://ubuntu.com/engage/secure-kubernetes-at-the-edge * Introducing Expanded Security Maintenance for Applications. Receive updates to over 25,000 software packages with your Ubuntu Pro subscription. Free for personal use. https://ubuntu.com/pro Expanded Security Maintenance for Applications is not enabled. 28 updates can be applied immediately. To see these additional updates run: apt list --upgradable Enable ESM Apps to receive additional future security updates. See https://ubuntu.com/esm or run: sudo pro status Last login: Sun Apr 2 14:14:49 2023 from 192.168.1.13 ahens@kubeworker:~$
-
Tried ping and its working.
root@kubemaster:/etc/ansible/playbook/modules/service# ping webserver1 PING webserver1 (192.168.1.12) 56(84) bytes of data. 64 bytes from webserver1 (192.168.1.12): icmp_seq=1 ttl=64 time=3.12 ms 64 bytes from webserver1 (192.168.1.12): icmp_seq=2 ttl=64 time=1.97 ms 64 bytes from webserver1 (192.168.1.12): icmp_seq=3 ttl=64 time=2.97 ms 64 bytes from webserver1 (192.168.1.12): icmp_seq=4 ttl=64 time=3.01 ms 64 bytes from webserver1 (192.168.1.12): icmp_seq=5 ttl=64 time=2.95 ms --- webserver1 ping statistics --- 5 packets transmitted, 5 received, 0% packet loss, time 4010ms rtt min/avg/max/mdev = 1.969/2.802/3.121/0.421 ms
Please someone tell me what is the issue.
2
Answers
First of all do not use ansible with root user directly, always use
become
.You might have your root user locked since You can not login with it(if You are sure credential is okay).
From your
webserver1
host runsudo passwd -S root
. it will show You something like:L
means user is locked and you need to unlock it.You can do it using
sudo usermod -U root
or simply by setting a new password for root user withsudo passwd root
.If this does not fix your problem, i’d suggest to check
/var/log/auth.log
file and check the failure reason.Your inventory file has some misprints:
Try this one: