become sudo not working for apt module

43 views
Skip to first unread message

Gregory Machin

unread,
May 13, 2024, 10:42:21 PM5/13/24
to Ansible Project
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

Stefan Hornburg (Racke)

unread,
May 14, 2024, 1:38:34 AM5/14/24
to ansible...@googlegroups.com
Hello Greg,

you miss "become: true" in your playbook-

Regards
Racke

>
> --
> You received this message because you are subscribed to the Google Groups "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com <mailto:ansible-proje...@googlegroups.com>.
> To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/5247dc46-a89e-4685-97af-53f8b91c8be8n%40googlegroups.com <https://groups.google.com/d/msgid/ansible-project/5247dc46-a89e-4685-97af-53f8b91c8be8n%40googlegroups.com?utm_medium=email&utm_source=footer>.

--
Automation expert - Ansible and friends
Linux administrator & Debian maintainer
Perl Dancer & conference hopper


John Petro

unread,
May 14, 2024, 5:34:15 AM5/14/24
to ansible...@googlegroups.com
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 

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/5247dc46-a89e-4685-97af-53f8b91c8be8n%40googlegroups.com.

Brian Coca

unread,
May 14, 2024, 10:45:05 AM5/14/24
to ansible...@googlegroups.com
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.


--
----------
Brian Coca (he/him/yo)

Reply all
Reply to author
Forward
0 new messages