# Playbook error-- "Failed to lock apt for exclusive operation"

**URL:** <https://forum.ansible.com/t/playbook-error-failed-to-lock-apt-for-exclusive-operation/30845>\
**Category:** Ansible Project\
**Created:** [July 23, 2019, 9:29am UTC](https://forum.ansible.com/t/playbook-error-failed-to-lock-apt-for-exclusive-operation/30845 "2019-07-23T09:29:45Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dhamodharan\_D](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@Dhamodharan\_D](https://forum.ansible.com/u/Dhamodharan_D)\
**Post date:** [July 23, 2019, 9:29am UTC](https://forum.ansible.com/t/playbook-error-failed-to-lock-apt-for-exclusive-operation/30845/1 "2019-07-23T09:29:45Z")

</div>

Hi All,

I have configured ansible properly with 1 master and 1 node machine. Have configured the /etc/ansible/hosts file with

[webservers]  
172.31.xx.xx ansible\_ssh\_user=ansibleuser ansible\_ssh\_pass=passwd.

and have written my playbook for installing apache webserver in node machine.

 ![playerror.PNG](https://us1.discourse-cdn.com/ansible/original/2X/2/25f249261737bafe88fbc0b31e1860468c7df4da.png)

After execting my playbook, I am getting this error.

Note: When I execute the same playbook on hosts: localhost. its working fine.

Can somone help me to fix the issue.

Thanks.

Regards,  
Dhamodharan.

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [July 23, 2019, 9:38am UTC](https://forum.ansible.com/t/playbook-error-failed-to-lock-apt-for-exclusive-operation/30845/2 "2019-07-23T09:38:05Z")

</div>

This usually happens when there is another apt operation going on.  
I sometimes have this if I spin up an instance from an image that is a  
bit old and it has to download a lot of security updates.

Dick

---

<div class="post-metadata">

**Author:** ![Dhamodharan\_D](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@Dhamodharan\_D](https://forum.ansible.com/u/Dhamodharan_D)\
**Post date:** [July 23, 2019, 9:46am UTC](https://forum.ansible.com/t/playbook-error-failed-to-lock-apt-for-exclusive-operation/30845/3 "2019-07-23T09:46:43Z")

</div>

Hi Dick,

Thanks for your revert, but I dont have any other apt operation running on my machine. Its a fresh machine and just configured for ansible operation and tried apache configuration in my ansible node.

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [July 23, 2019, 10:37am UTC](https://forum.ansible.com/t/playbook-error-failed-to-lock-apt-for-exclusive-operation/30845/4 "2019-07-23T10:37:08Z")

</div>

I assume you have become=yes?

---

<div class="post-metadata">

**Author:** ![Dhamodharan\_D](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@Dhamodharan\_D](https://forum.ansible.com/u/Dhamodharan_D)\
**Post date:** [July 23, 2019, 10:45am UTC](https://forum.ansible.com/t/playbook-error-failed-to-lock-apt-for-exclusive-operation/30845/5 "2019-07-23T10:45:30Z")

</div>

That also I have tried, even tried with sudo=yes, become\_user=yes, remote\_user=.

Nothing worked out…

---

<div class="post-metadata">

**Author:** ![Dhamodharan\_D](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@Dhamodharan\_D](https://forum.ansible.com/u/Dhamodharan_D)\
**Post date:** [July 23, 2019, 10:47am UTC](https://forum.ansible.com/t/playbook-error-failed-to-lock-apt-for-exclusive-operation/30845/6 "2019-07-23T10:47:10Z")

</div>

That also I have tried, even tried with sudo=yes, become\_user=yes, remote\_user=.

Nothing worked out…

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [July 23, 2019, 11:24am UTC](https://forum.ansible.com/t/playbook-error-failed-to-lock-apt-for-exclusive-operation/30845/7 "2019-07-23T11:24:03Z")

</div>

I would expect that when trying combinations of (partially outdated)  
privilege escalation directives and random values.  
However, it does indicate that privilege escalation \_is\_ the actual  
problem though.

Please take a few minutes to read  
[https://docs.ansible.com/ansible/latest/user\_guide/become.html](https://docs.ansible.com/ansible/latest/user_guide/become.html), and  
adjust your playbook and ansible invocation accordingly.

Dick
