# Using apt gives error

**URL:** <https://forum.ansible.com/t/using-apt-gives-error/11226>\
**Category:** Get Help\
**Tags:** playbook\
**Created:** [November 29, 2024, 11:46am UTC](https://forum.ansible.com/t/using-apt-gives-error/11226 "2024-11-29T11:46:22Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![capbussat](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/capbussat/32/5592_2.png) [@capbussat](https://forum.ansible.com/u/capbussat)\
**Post date:** [November 29, 2024, 11:46am UTC](https://forum.ansible.com/t/using-apt-gives-error/11226/1 "2024-11-29T11:46:22Z")

</div>

I am trying to use a playbook with ansible.builtin.apt but I get a sudo error.  
I am using a user, which is not root, that effectively uses sudo in target host.  
In /etc/ansible/hosts there is the IP of host with user and password

‘’'10.1.1.102 ansible\_ssh\_pass=‘_password_’ ansible\_ssh\_user=‘_username_’

Error:

```auto
fatal: [10.1.1.102]: FAILED! => {"changed": false, "msg": "'/usr/bin/apt-get upgrade --with-new-pkgs ' failed: E: Could not open lock file /var/lib/dpkg/lock-frontend - open (13: Permission denied)\nE: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), are you root?\n", "rc": 100, "stdout": "", "stdout_lines": []}

My playbook is like

```

- name: Update all packages to their latest version  
ansible.builtin.apt:  
name: “\*”  
state: latest

---

<div class="post-metadata">

**Author:** ![dnmvisser](https://avatars.discourse-cdn.com/v4/letter/d/8e8cbc/32.png) [@dnmvisser](https://forum.ansible.com/u/dnmvisser)\
**Post date:** [November 29, 2024, 11:59am UTC](https://forum.ansible.com/t/using-apt-gives-error/11226/2 "2024-11-29T11:59:25Z")

</div>

> > > |
> > 
> > - | - |
> 
> I am using a user, which is not root, that effectively uses sudo in target host.

What exactly does “effectively uses sudo” mean?  
You have to use “become: true” for this user, and it should be able to use unrestricted sudo.  
Anything else will not work.

Dick

---

<div class="post-metadata">

**Author:** ![capbussat](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/capbussat/32/5592_2.png) [@capbussat](https://forum.ansible.com/u/capbussat)\
**Post date:** [November 29, 2024, 3:06pm UTC](https://forum.ansible.com/t/using-apt-gives-error/11226/3 "2024-11-29T15:06:30Z")

</div>

Thanks Dick, in which file I have to use become=true?  
playbook?  
/etc/ansible/hosts  
ansible.cfg ?

Sorry for my bad explanation. I mean that I use this ‘username’ in my host with sudo everyday and works fine.  
It’s my first week exploring Ansible.

---

<div class="post-metadata">

**Author:** ![capbussat](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/capbussat/32/5592_2.png) [@capbussat](https://forum.ansible.com/u/capbussat)\
**Post date:** [November 29, 2024, 3:43pm UTC](https://forum.ansible.com/t/using-apt-gives-error/11226/4 "2024-11-29T15:43:21Z")

</div>

I found the solution Two things:  
Firs, obviously include become: true in the playbook

 ![Captura de pantalla 2024-11-29 164159](https://us1.discourse-cdn.com/ansible/original/2X/f/f9566f4d11ba2e3467844b8e1123d98dd4860741.png)  
Second, ask for password in command line:  
ansible-playbook playbook.yaml --ask-become-pass

---

<div class="post-metadata">

**Author:** ![dnmvisser](https://avatars.discourse-cdn.com/v4/letter/d/8e8cbc/32.png) [@dnmvisser](https://forum.ansible.com/u/dnmvisser)\
**Post date:** [November 29, 2024, 4:59pm UTC](https://forum.ansible.com/t/using-apt-gives-error/11226/5 "2024-11-29T16:59:22Z")

</div>

Yes thats what works in your situation 👍
