Debug School

Mohammad Gufran Jahangir
Mohammad Gufran Jahangir

Posted on

Ansible Error : "Missing sudo password"

Error

root@master:~# ansible all -i inventory -m apt -a"name=apache2 state=present" -u jami -k -b
root@master:~# SSH password: 
192.168.1.42 | FAILED! => {
    "msg": "Missing sudo password"
Enter fullscreen mode Exit fullscreen mode

Solution

The error message indicates that the sudo password is missing. When using the -b flag (become), Ansible requires the sudo password to escalate privileges on the remote machine. To resolve this issue, you have a few options:

1. Provide the sudo password using the --ask-become-pass flag:

ansible all -i inventory -m apt -a "name=apache2 state=present" -u jami -k -b --ask-become-pass

Enter fullscreen mode Exit fullscreen mode

This command will prompt you to enter the sudo password interactively.

2. If you don't want to enter the sudo password every time, you can configure the sudo password in your Ansible configuration file. Open the ansible.cfg file (usually located in the project directory or /etc/ansible/) and add the following line under the [privilege_escalation] section:

become_ask_pass = False

Enter fullscreen mode Exit fullscreen mode

This will prevent Ansible from prompting for the sudo password. However, keep in mind that it may introduce security risks, so use this option cautiously.

3. If you have SSH key-based authentication set up for the remote machine, you can use the --private-key option to specify the private key file instead of using password-based authentication:

ansible all -i inventory -m apt -a "name=apache2 state=present" -u jami --private-key=/path/to/private_key -b

Enter fullscreen mode Exit fullscreen mode

Replace /path/to/private_key with the actual path to your private key file.

Top comments (0)