ESvi3
ESvi3

Reputation: 95

Ansible still asking for sudo with a passwordless user

I have just started learning ansible , i configured a simple playbook where m running a apt install command using a passwordless remote user (called ansible) and added the become:true as shown in the code below.

---

- name: managig the ubuntu servers
  hosts: ubuntu_servers
  remote_user: ansible
  become: true
  become_method: sudo
  become_user: root
  tasks:
    - name: Installing a pcakage on ubuntu servers
      apt:
        name: traceroute
        state: present
        update_cache: true

I am positive that the user ansible is configured as a passwordless sudoer , since I've tested it directly on the servers , but m alwasy getting this error


fatal: [server2]: FAILED! => {"msg": "Missing sudo password"}


fatal: [server3]: FAILED! => {"msg": "Missing sudo password"}

Upvotes: 1

Views: 62

Answers (1)

Alwyn
Alwyn

Reputation: 1

I think the issue comes from the remote_user. You specified remote_user in the hosts context, but seems like it doesn't work. I did some small test:

default group in inventory file

<server name> ansible_host=<host ip> ansible_user=jenkins ansible_ssh_common_args='-o StrictHostKeyChecking=no'

my playbook

---
- name: test
  hosts: default
  remote_user: wvcuser
  tasks:
    - name: whoami
      shell: whoami
      register: output

    - debug:
        var: output.stdout

The output:

...
ok: [devserver1] => {
    "output.stdout": "jenkins"
}
...

A stratforward way is to use ansible_user. So, you have to check the ansible_user in your inventory file is "ansible", or make it sudo-able

Upvotes: 0

Related Questions