Vagrant / Ansible, Could not get lock /var/lib/dpkg/lock

Problem

To save time when provisioning and reduce the size of VMs using linked clones, I packaged a pre-provisioned Vagrant box as a base to use with standard LAMP apps.

Ansible still provisions on vagrant up to customize the box for the project, and it periodically fails with the error

Could not get lock /var/lib/dpkg/lock - open (11: Resource temporarily unavailable)
Unable to lock the administration directory (/var/lib/dpkg/), is another process using it?

Solution

A bit of searching led me to this similar issue.

Instead of changing the provisioning, I made the suggested periodic configuration change in the base box:

$ sudo sh -c "echo 'APT::Periodic::Enable \"0\";' > /etc/apt/apt.conf.d/02periodic"

Then, I repackaged the box to use it as a base, with the configuration already set.

So far this appears to have solved the problem.

Add new comment