diagnose error within a loop

Hi,

Here is my task and variable description:

packages:
kvm:
libvirt-bin:
libvirt-dev:
libxml2-dev:
libxslt-dev:

  • name: Install libvirt packages

apt: state=latest name={{ item.key }}
sudo: yes
with_dict: packages

The problem is that some unknown process is running apt or dpkg during the execution of my playbook, causing the install of some of the packages to fail (though some do succeed). In most cases, the conflict is gone before the last package is installed. I’d like to be able to insert some diagnostics to find out what else is running, but I don’t know how to do this in the context of this loop. I have a small sequence of commands that will describe the processes with /var/lib/dkpg/lock open and their parents, which I think would be helpful if I could get it to run at the right time.

Note that this is in a CI test where the VM being used is not available for instrumentation/inspection before/after the test. I’ve already asked the owner of the CI system to ensure that the VMs used for the test do not automatically update anything.

FYI, the error I see when the install fails:

2015-07-27 06:41:29.177 | stderr: E: Could not get lock /var/lib/dpkg/lock - open (11: Resource temporarily unavailable)
2015-07-27 06:41:29.178 | E: Unable to lock the administration directory (/var/lib/dpkg/), is another process using it?

Thanks in advance,
Chuck