# become sudo not working for apt module

**URL:** <https://forum.ansible.com/t/become-sudo-not-working-for-apt-module/38780>\
**Category:** Ansible Project\
**Tags:** ubuntu, awx\
**Created:** [May 14, 2024, 2:42am UTC](https://forum.ansible.com/t/become-sudo-not-working-for-apt-module/38780 "2024-05-14T02:42:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gregory\_Machin](https://avatars.discourse-cdn.com/v4/letter/g/e5b9ba/32.png) [@Gregory\_Machin](https://forum.ansible.com/u/Gregory_Machin)\
**Post date:** [May 14, 2024, 2:42am UTC](https://forum.ansible.com/t/become-sudo-not-working-for-apt-module/38780/1 "2024-05-14T02:42:21Z")

</div>

Hi

I have a number of ubuntu servers that I want to update using ansible via AWX. my current test playbook :

---

<div class="post-metadata">

**Author:** ![jcpetro](https://avatars.discourse-cdn.com/v4/letter/j/53a042/32.png) [@jcpetro](https://forum.ansible.com/u/jcpetro)\
**Post date:** [May 14, 2024, 3:13am UTC](https://forum.ansible.com/t/become-sudo-not-working-for-apt-module/38780/2 "2024-05-14T03:13:26Z")

</div>

Have you tried a ps on the host you are trying to upgrade to see if an apt command is already running? I’ve run into it before where an auto update is running, so it has the lock file already in place.

–john

---

<div class="post-metadata">

**Author:** ![racke](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/racke/32/4767_2.png) [@racke](https://forum.ansible.com/u/racke)\
**Post date:** [May 14, 2024, 5:38am UTC](https://forum.ansible.com/t/become-sudo-not-working-for-apt-module/38780/3 "2024-05-14T05:38:01Z")

</div>

> Hi
> 
> I have a number of ubuntu servers that I want to update using ansible via AWX. my current test playbook :
> 
> ---  
> - hosts: all  
> tasks:  
> - name: Test Connection  
> ansible.builtin.ping:
> 
> ```
> \- name: Update Cache
> become: true
> apt:
> update\_cache: true
> 
> ```
> 
> is not work as expected on the ubuntu servers.  
> The servers that have the root user configured are fine. But the Ubuntu servers where the root user doesn't have a password set are failing with the following error:
> 
> "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)"
> 
> In AWX I have configured privilege escalation to use sudo but this doesnt help.
> 
> I have tried moving the become: yes statement but this did help.
> 
> Doe the apt module support the sudo ?
> 
> What have I missed ?
> 
> Thank you
> 
> Greg

Hello Greg,

you miss "become: true" in your playbook-

Regards  
&nbsp;&nbsp;&nbsp;Racke

---

<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:** [May 14, 2024, 2:44pm UTC](https://forum.ansible.com/t/become-sudo-not-working-for-apt-module/38780/4 "2024-05-14T14:44:23Z")

</div>

FYI, become is independent of modules, it wraps module execution so  
modules do not need to enable/support it. Connection plugins on the  
other hand can affect how become works, in the case of local, windows  
and networking appliances.
