I'm creating an Ansible Playbook to set up Ubuntu 18.04.1 VPSs and am encountering a problem where I can't reliably install Python.

Since Ubuntu 18.04.1 is not shipping with Python installed, I'm forced to use the following command apt -y update && apt -y install python with the raw module.

I've also managed to get this error in a shell into which I manually ssh'd into.

root@ansible:~# apt -y update && apt -y install python
Hit:1 http://archive.ubuntu.com/ubuntu bionic InRelease
Hit:2 http://archive.ubuntu.com/ubuntu bionic-security InRelease
Hit:3 http://archive.ubuntu.com/ubuntu bionic-updates InRelease
Reading package lists... Done
Building dependency tree
Reading state information... Done
17 packages can be upgraded. Run 'apt list --upgradable' to see them.
E: Could not get lock /var/lib/dpkg/lock - open (11: Resource temporarily unavailable)
E: Unable to lock the administration directory (/var/lib/dpkg/), is another process using it?

This is a Virtual Machine in VirtualBox on a Windows host.

I've also tried with using sync between apt update and apt install, even doing something like this while fuser /var/lib/dpkg/lock >/dev/null 2>&1; do sync && sleep 1; done between update and install, but it usually fails.

It is a system which has been set up with the following steps: https://askubuntu.com/questions/946787/ubuntu-server-installation-with-root-only/1066033#1066033


Ubuntu 16.04+, iirc, ship with Python3 by default and have removed Python2 entirely from the default install; in other words, there is a functioning Python interpreter, it's just not in a place Ansible looks.

You can override the default behavior (expecting python as a command) by using the ansible_python_interpreter variable and setting it to, in the case of Ubuntu 16.04+, /usr/bin/python3.

So something like this: ansible_python_interpreter: /usr/bin/python3

Ansible now treats Python3 as a first-class citizen for the most part, so this is a pretty safe change. I've been using it on a handful of Ubuntu 18.04 boxes I administer with no issues.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.