I suspect that Steve's suggestion should fix this mostly for cloud-init.
Apt does of course have a general locking problem that really does need addressing.
We've all seen workarounds/retries at all sorts of levels to address the problems that
a.) you basically have to run 'apt-get update' before you run 'apt-get install' (bug 1429285), which results in the over-usage of that fairly heavy resource.
b.) if another process is running 'apt-get install' or 'apt-get remove' when you attempt, you will fail with the lock contention.
These things should be solved in apt, not worked around in yet another process that uses it.
I suspect that Steve's suggestion should fix this mostly for cloud-init.
Apt does of course have a general locking problem that really does need addressing.
We've all seen workarounds/retries at all sorts of levels to address the problems that
a.) you basically have to run 'apt-get update' before you run 'apt-get install' (bug 1429285), which results in the over-usage of that fairly heavy resource.
b.) if another process is running 'apt-get install' or 'apt-get remove' when you attempt, you will fail with the lock contention.
These things should be solved in apt, not worked around in yet another process that uses it.