# msg: Failed to lock apt for exclusive operation - apt: update\_cache=yes

**URL:** <https://forum.ansible.com/t/msg-failed-to-lock-apt-for-exclusive-operation-apt-update-cache-yes/16374>\
**Category:** Ansible Project\
**Tags:** ubuntu\
**Created:** [September 29, 2014, 7:08pm UTC](https://forum.ansible.com/t/msg-failed-to-lock-apt-for-exclusive-operation-apt-update-cache-yes/16374 "2014-09-29T19:08:16Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eric\_Brooke](https://avatars.discourse-cdn.com/v4/letter/e/d07c76/32.png) [@Eric\_Brooke](https://forum.ansible.com/u/Eric_Brooke)\
**Post date:** [September 29, 2014, 7:08pm UTC](https://forum.ansible.com/t/msg-failed-to-lock-apt-for-exclusive-operation-apt-update-cache-yes/16374/1 "2014-09-29T19:08:16Z")

</div>

Hello,

Last week we updated one of our servers from unbent 12.0+ to 14.0+ it deployed with out issue, after the weekend deployment to one of servers is no longer possible ☹

Here is the command that is failing:

- name: Update the apt cache if older than 2 hrs  
apt: update\_cache=yes cache\_valid\_time=7200  
tags:
- security-apt

On just one of our servers prd1

TASK: [common | Update the apt cache if older than 2 hrs] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
 ESTABLISH CONNECTION FOR USER: ubuntu  
 ESTABLISH CONNECTION FOR USER: ubuntu  
 REMOTE\_MODULE apt update\_cache=yes cache\_valid\_time=7200  
 REMOTE\_MODULE apt update\_cache=yes cache\_valid\_time=7200  
 EXEC [‘ssh’, ‘-C’, ‘-tt’, ‘-q’, ‘-o’, ‘ControlMaster=auto’, ‘-o’, ‘ControlPersist=60s’, ‘-o’, ‘ControlPath=/Users/ericbrooke/.ansible/cp/ansible-ssh-%h-%p-%r’, ‘-o’, ‘KbdInteractiveAuthentication=no’, ‘-o’, ‘PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey’, ‘-o’, ‘PasswordAuthentication=no’, ‘-o’, ‘User=ubuntu’, ‘-o’, ‘ConnectTimeout=10’, ‘prd1’, “/bin/sh -c ‘mkdir -p $HOME/.ansible/tmp/ansible-tmp-1412016466.77-35664788881142 && chmod a+rx $HOME/.ansible/tmp/ansible-tmp-1412016466.77-35664788881142 && echo $HOME/.ansible/tmp/ansible-tmp-1412016466.77-35664788881142’”]  
 EXEC [‘ssh’, ‘-C’, ‘-tt’, ‘-q’, ‘-o’, ‘ControlMaster=auto’, ‘-o’, ‘ControlPersist=60s’, ‘-o’, ‘ControlPath=/Users/ericbrooke/.ansible/cp/ansible-ssh-%h-%p-%r’, ‘-o’, ‘KbdInteractiveAuthentication=no’, ‘-o’, ‘PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey’, ‘-o’, ‘PasswordAuthentication=no’, ‘-o’, ‘User=ubuntu’, ‘-o’, ‘ConnectTimeout=10’, ‘prd3’, “/bin/sh -c ‘mkdir -p $HOME/.ansible/tmp/ansible-tmp-1412016466.77-191935961010276 && chmod a+rx $HOME/.ansible/tmp/ansible-tmp-1412016466.77-191935961010276 && echo $HOME/.ansible/tmp/ansible-tmp-1412016466.77-191935961010276’”]  
 PUT /var/folders/dz/\_g3k142j3vz652trrswwwxf80000gq/T/tmpnz2A7A TO /home/ubuntu/.ansible/tmp/ansible-tmp-1412016466.77-191935961010276/apt  
 PUT /var/folders/dz/\_g3k142j3vz652trrswwwxf80000gq/T/tmp0xdCki TO /home/ubuntu/.ansible/tmp/ansible-tmp-1412016466.77-35664788881142/apt  
 EXEC [‘ssh’, ‘-C’, ‘-tt’, ‘-q’, ‘-o’, ‘ControlMaster=auto’, ‘-o’, ‘ControlPersist=60s’, ‘-o’, ‘ControlPath=/Users/ericbrooke/.ansible/cp/ansible-ssh-%h-%p-%r’, ‘-o’, ‘KbdInteractiveAuthentication=no’, ‘-o’, ‘PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey’, ‘-o’, ‘PasswordAuthentication=no’, ‘-o’, ‘User=ubuntu’, ‘-o’, ‘ConnectTimeout=10’, ‘prd1’, u’/bin/sh -c 'sudo -k && sudo -H -S -p “[sudo via ansible, key=XXX] password: " -u root /bin/sh -c '”'“'echo SUDO-SUCCESS-XXX; LANG=en\_US.UTF-8 LC\_CTYPE=en\_US.UTF-8 /usr/bin/python /home/ubuntu/.ansible/tmp/ansible-tmp-1412016466.77-35664788881142/apt; rm -rf /home/ubuntu/.ansible/tmp/ansible-tmp-1412016466.77-35664788881142/ \>/dev/null 2\>&1'”'“''‘]  
 EXEC [‘ssh’, ‘-C’, ‘-tt’, ‘-q’, ‘-o’, ‘ControlMaster=auto’, ‘-o’, ‘ControlPersist=60s’, ‘-o’, ‘ControlPath=/Users/ericbrooke/.ansible/cp/ansible-ssh-%h-%p-%r’, ‘-o’, ‘KbdInteractiveAuthentication=no’, ‘-o’, ‘PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey’, ‘-o’, ‘PasswordAuthentication=no’, ‘-o’, ‘User=ubuntu’, ‘-o’, ‘ConnectTimeout=10’, ‘prd3’, u’/bin/sh -c 'sudo -k && sudo -H -S -p “[sudo via ansible, key=XXX] password: " -u root /bin/sh -c '”'”'echo SUDO-SUCCESS-XXX; LANG=en\_US.UTF-8 LC\_CTYPE=en\_US.UTF-8 /usr/bin/python /home/ubuntu/.ansible/tmp/ansible-tmp-1412016466.77-191935961010276/apt; rm -rf /home/ubuntu/.ansible/tmp/ansible-tmp-1412016466.77-191935961010276/ \>/dev/null 2\>&1'“'”''']  
ok: [prd3 =\> {“changed”: false}  
failed: [prd1] =\> {“failed”: true}

I have replaced the keys with XXX

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [September 30, 2014, 7:23pm UTC](https://forum.ansible.com/t/msg-failed-to-lock-apt-for-exclusive-operation-apt-update-cache-yes/16374/2 "2014-09-30T19:23:04Z")

</div>

Anything relevant in the logs?

---

<div class="post-metadata">

**Author:** ![Eric\_Brooke](https://avatars.discourse-cdn.com/v4/letter/e/d07c76/32.png) [@Eric\_Brooke](https://forum.ansible.com/u/Eric_Brooke)\
**Post date:** [September 30, 2014, 8:02pm UTC](https://forum.ansible.com/t/msg-failed-to-lock-apt-for-exclusive-operation-apt-update-cache-yes/16374/3 "2014-09-30T20:02:37Z")

</div>

Which logs would you like to see?

---

<div class="post-metadata">

**Author:** ![Eric\_Brooke](https://avatars.discourse-cdn.com/v4/letter/e/d07c76/32.png) [@Eric\_Brooke](https://forum.ansible.com/u/Eric_Brooke)\
**Post date:** [September 30, 2014, 8:37pm UTC](https://forum.ansible.com/t/msg-failed-to-lock-apt-for-exclusive-operation-apt-update-cache-yes/16374/4 "2014-09-30T20:37:22Z")

</div>

I fixed it with a server reboot. Is there a place to restart this service rather then the whole server. Any advice appreciated. Thanks in advance

---

<div class="post-metadata">

**Author:** ![Brian\_Coca1](https://avatars.discourse-cdn.com/v4/letter/b/278dde/32.png) [@Brian\_Coca1](https://forum.ansible.com/u/Brian_Coca1)\
**Post date:** [September 30, 2014, 9:04pm UTC](https://forum.ansible.com/t/msg-failed-to-lock-apt-for-exclusive-operation-apt-update-cache-yes/16374/5 "2014-09-30T21:04:41Z")

</div>

not a service, locks on the apt DB are done to avoid inconsistencies,  
either someone else was running an update or a lock got leftover  
(probably with a hung/interrupted process).

you can normally use lsof to find out what the offending process is  
and kill it, restart fixed it by killing ALL processes.

---

<div class="post-metadata">

**Author:** ![Eric\_Brooke](https://avatars.discourse-cdn.com/v4/letter/e/d07c76/32.png) [@Eric\_Brooke](https://forum.ansible.com/u/Eric_Brooke)\
**Post date:** [September 30, 2014, 10:33pm UTC](https://forum.ansible.com/t/msg-failed-to-lock-apt-for-exclusive-operation-apt-update-cache-yes/16374/6 "2014-09-30T22:33:44Z")

</div>

Thank you Brian
