Score:0

Strange behavior of dpkg with ansible

in flag
Aki

As part of my workflow I'm using Ubuntu server 20.04.3.

So I prepare the image for the VM and deploy it using Ansible.

Since it is env with no access to the internet all packages I'm installing have been previously downloaded .deb. by execution simple shell command:

dpkg -i deb_1.deb  deb_2.deb deb_3.deb deb_4.deb 
dpkg -i deb_5.deb  deb_6.deb deb_7.deb deb_8.deb 

Sometimes ~5% of cases, I'm receiving this error totally sporadically, can occur on first installation

"stderr_lines": ["dpkg: error: dpkg frontend lock is locked by another process",
"E: Sub-process dpkg --set-selections returned an error code (2)", "E: Executing dpkg failed. Are you root?"]

I have tried to solve this by:

  1. List item

Before each installation step perform manual lock file deletion

  • /var/lib/dpkg/lock
  • /var/lib/dpkg/lock-frontend
  • /var/cache/apt/archives/lock

But even after manual deletion the error continue to appears.

  1. Tried to install packages with Ansible apt module and "deb" arg - but the behavior is the same.

  2. Tried to figure out what process actually owns the lock files with "lsof", but file was not owned by any process.

Is there is some way to fix this strange and buggy behavior?

What process is responsible for creating lock files sometimes on system startup?

Score:0
cn flag

The answer is in the message:

Executing dpkg failed. Are you root?

You need to put sudo in front of the command when altering system owned locations.

Aki avatar
in flag
Aki
I'm running all commands with sudo privileges', also I mentioned that this error is rare, and in most cases it is work, hence this is not permission related issue, unfortunately
cn flag
dpkg seems to think you are not so you probably need to check on how you set sudo up: you omitted it in front of the commands. Pretty dangerous if you added dpkg to the sudoers file: that will NOT allow you to execute commands inside the package.
Aki avatar
in flag
Aki
Im logging in as a root user, so it is not needed to use sudo.
cn flag
Ubuntu is not set up to be used as root and it could very well be that this is a side-effect. When you get this error drop to the admin user and use `sudo` with dpkg` If that works you found the reason for your problem. If you want to use root you could switch to Debian. The comment you made is CRUCIAL information and should have been in the question and I could have ignored the question.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.