Could not get lock /var/lib/dpkg/lock-frontend

Hello,

I’m trying to create an image in GCP, but I’m getting the next error:

==> googlecompute: Provisioning with shell script: /var/folders/c6/t49g6krj66ld0wq8q13x9rg80000gn/T/packer-shell399635902
    googlecompute: Hit:1 http://europe-west1.gce.archive.ubuntu.com/ubuntu bionic InRelease
    googlecompute: Get:2 http://europe-west1.gce.archive.ubuntu.com/ubuntu bionic-updates InRelease [88.7 kB]
    googlecompute: Get:3 http://europe-west1.gce.archive.ubuntu.com/ubuntu bionic-backports InRelease [74.6 kB]
    googlecompute: Get:4 http://security.ubuntu.com/ubuntu bionic-security InRelease [88.7 kB]
    googlecompute: Get:5 http://archive.canonical.com/ubuntu bionic InRelease [10.2 kB]
    googlecompute: Get:6 https://download.docker.com/linux/ubuntu bionic InRelease [64.4 kB]
    googlecompute: Get:7 http://apt.puppetlabs.com bionic InRelease [85.3 kB]
    googlecompute: Get:8 http://europe-west1.gce.archive.ubuntu.com/ubuntu bionic-updates/main amd64 Packages [859 kB]
    googlecompute: Get:9 http://europe-west1.gce.archive.ubuntu.com/ubuntu bionic-updates/main Translation-en [300 kB]
    googlecompute: Get:10 http://europe-west1.gce.archive.ubuntu.com/ubuntu bionic-updates/restricted amd64 Packages [31.2 kB]
    googlecompute: Get:11 http://europe-west1.gce.archive.ubuntu.com/ubuntu bionic-updates/restricted Translation-en [8128 B]
    googlecompute: Get:12 http://europe-west1.gce.archive.ubuntu.com/ubuntu bionic-updates/universe amd64 Packages [1051 kB]
    googlecompute: Get:13 http://europe-west1.gce.archive.ubuntu.com/ubuntu bionic-updates/universe Translation-en [325 kB]
    googlecompute: Get:14 http://europe-west1.gce.archive.ubuntu.com/ubuntu bionic-updates/multiverse amd64 Packages [9700 B]
    googlecompute: Get:15 http://europe-west1.gce.archive.ubuntu.com/ubuntu bionic-updates/multiverse Translation-en [4576 B]
    googlecompute: Get:16 http://europe-west1.gce.archive.ubuntu.com/ubuntu bionic-backports/universe amd64 Packages [4028 B]
    googlecompute: Get:17 http://europe-west1.gce.archive.ubuntu.com/ubuntu bionic-backports/universe Translation-en [1900 B]
    googlecompute: Get:18 http://security.ubuntu.com/ubuntu bionic-security/main amd64 Packages [636 kB]
    googlecompute: Get:19 http://security.ubuntu.com/ubuntu bionic-security/main Translation-en [208 kB]
    googlecompute: Get:20 http://security.ubuntu.com/ubuntu bionic-security/restricted amd64 Packages [21.2 kB]
    googlecompute: Get:21 http://security.ubuntu.com/ubuntu bionic-security/restricted Translation-en [5984 B]
    googlecompute: Get:22 http://security.ubuntu.com/ubuntu bionic-security/universe amd64 Packages [645 kB]
    googlecompute: Get:23 http://security.ubuntu.com/ubuntu bionic-security/universe Translation-en [217 kB]
    googlecompute: Get:24 http://security.ubuntu.com/ubuntu bionic-security/multiverse amd64 Packages [6340 B]
    googlecompute: Get:25 http://security.ubuntu.com/ubuntu bionic-security/multiverse Translation-en [2640 B]
    googlecompute: Get:26 http://archive.canonical.com/ubuntu bionic/partner amd64 Packages [2292 B]
    googlecompute: Get:27 http://archive.canonical.com/ubuntu bionic/partner Translation-en [1332 B]
    googlecompute: Get:28 https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages [10.3 kB]
    googlecompute: Get:29 http://apt.puppetlabs.com bionic/puppet all Packages [16.4 kB]
    googlecompute: Get:30 http://apt.puppetlabs.com bionic/puppet amd64 Packages [39.9 kB]
    googlecompute: Fetched 4818 kB in 7s (661 kB/s)
    googlecompute: Reading package lists...
==> googlecompute: E: Could not get lock /var/lib/dpkg/lock-frontend - open (11: Resource temporarily unavailable)
==> googlecompute: E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), is another process using it?
==> googlecompute: Provisioning step had errors: Running the cleanup provisioner, if present...
==> googlecompute: Deleting instance...
    googlecompute: Instance has been deleted!
==> googlecompute: Deleting disk...
    googlecompute: Disk has been deleted!
Build 'googlecompute' errored: Script exited with non-zero exit status: 100.Allowed exit codes are: [0]

==> Some builds didn't complete successfully and had errors:
--> googlecompute: Script exited with non-zero exit status: 100.Allowed exit codes are: [0]

==> Builds finished but no artifacts were created.

Do you have any clue to solve this? I try to put and sleep on .json and run with PACKER_LOG=1 but, I’don’t get enough information.

Regards,

what is your ssh username, possibly you need to use sudo ???

OR

if the message is real, then it could be that the unattended-upgrades is running as soon as the machine starts.

Hi shantanugadgil,

thank for your answer, I put and wait before launch the provisioning, I enter to the machine and I check that was the unattended-upgrades. I solved it putting enough wait time.

Regards!

Cool. instead of a hard wait, you could also try a “while 1 … pgrep unattended …” Maybe?