# I can't get Ansible to recognize sudo

**URL:** <https://forum.ansible.com/t/i-cant-get-ansible-to-recognize-sudo/8773>\
**Category:** Get Help\
**Created:** [September 25, 2024, 8:18pm UTC](https://forum.ansible.com/t/i-cant-get-ansible-to-recognize-sudo/8773 "2024-09-25T20:18:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Enio\_Junior](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/enio_junior/32/4875_2.png) [@Enio\_Junior](https://forum.ansible.com/u/Enio_Junior)\
**Post date:** [September 25, 2024, 8:18pm UTC](https://forum.ansible.com/t/i-cant-get-ansible-to-recognize-sudo/8773/1 "2024-09-25T20:18:25Z")

</div>

I’m starting with Ansible but I’m having trouble using sudo. The configuration files look like this:  
ansible.cfg

```auto
[defaults]
ask_sudo_pass=True
editor=/usr/bin/micro
force-color=True
home=.
inventory=inventory.yml
nocolor=False
remote_port=2222
remote_user=eniocsj

[privilege_escalation]
become_ask_pass=True
become_exe=/usr/bin/sudo
become_user=eniocsj
become_method=sudo

```

playbook.yml

```auto
---
- name: Criação de um ambiente de desenvolvimento em background
  hosts: lab
  gather_facts: no
  become: yes
  remote_user: eniocsj
  become_method: sudo
  tasks:
    - name: Atualizando o cache do gerenciador de pacotes
      become: yes
      remote_user: eniocsj
      become_method: sudo
      ansible.builtin.apt:
        update_cache: yes

```

When calling the playbook, the following error is given:, When calling the playbook, the following error appears:

```auto
fatal: [182.168.1.2]: FAILED! => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python3.10"
    },
    "changed": false,
    "invocation": {
        "module_args": {
            "allow_change_held_packages": false,
            "allow_downgrade": false,
            "allow_unauthenticated": false,
            "autoclean": false,
            "autoremove": false,
            "cache_valid_time": 0,
            "clean": false,
            "deb": null,
            "default_release": null,
            "dpkg_options": "force-confdef,force-confold",
            "fail_on_autoremove": false,
            "force": false,
            "force_apt_get": false,
            "install_recommends": null,
            "lock_timeout": 60,
            "only_upgrade": false,
            "package": null,
            "policy_rc_d": null,
            "purge": false,
            "state": "present",
            "update_cache": true,
            "update_cache_retries": 5,
            "update_cache_retry_max_delay": 12,
            "upgrade": null
        }
    },
    "msg": "Failed to lock apt for exclusive operation: Failed to lock directory /var/lib/apt/lists/: E:Could not open lock file /var/lib/apt/lists/lock - open (13: Permission denied)"
}

```

It’s probably not calling sudo., Probably not calling sudo. Where am I going wrong?

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [September 25, 2024, 8:37pm UTC](https://forum.ansible.com/t/i-cant-get-ansible-to-recognize-sudo/8773/2 "2024-09-25T20:37:26Z")

</div>

> [@Enio\_Junior](#):
>
> `become_user=eniocsj`

You need to remove that configuration. That config tells ansible which user you want to become. It’s default value is `root`. If this is set to the same user as the `remote_user` then become is effectively ignored, since you are already the user that you want to become.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [October 25, 2024, 8:37pm UTC](https://forum.ansible.com/t/i-cant-get-ansible-to-recognize-sudo/8773/3 "2024-10-25T20:37:39Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
