Solvedansible Failure in apt. "Please install python-apt", but it is installed
✔️Accepted Answer
I ran into this issue using the local connection mode -c local
using ansible from a virtualenv. The difference between a working playbook and the broken virtualenv run is which python interpreter is used. In local mode, it uses the python in the virtualenv which doesn't have the apt packages. This doesn't matter when running the playbook in non-local mode to remote ssh hosts because the remote python is /usr/bin/python
. So I set the -e ansible_python_interpreter=/usr/bin/python
and it worked. The ansible code is still in the virtualenv and used on the driving host.
TL;DR try add -e ansible_python_interpreter=/usr/bin/python
to make your local ansible runs behave more like remote runs.
Other Answers:
Also for what it's worth. This issue also affects the latest release 2.1.2
I compiled python3.7 from the Cpython source code and wanted to use it as the ansible python interpreter on a host machine running Ubuntu 18.
I was able to overcome this "Please install python-apt" issue where I had ansible_python_interpreter=/usr/local/bin/python3.7
set as a host variable on the controlling machine.
On the host machine I first installed libapt-pkg-dev:
sudo apt install libapt-pkg-dev
I cloned the source code for python-apt:
git clone https://salsa.debian.org/apt-team/python-apt && cd python-apt
git checkout 1.6.2 # check versions via git tag
python3.7 setup.py build
python3.7 setup.py install
And then the "Please install python-apt" error was no longer returned from the host machine to the controlling machine.
I succeeded in running this playbook:
---
- hosts: all
become: yes
tasks:
- name: Update and upgrade apt packages
become: true
apt:
upgrade: yes
update_cache: yes
cache_valid_time: 86400 #One day
Issue Type:
COMPONENT NAME
apt
Ansible Version:
ansible 2.0.0.2
config file = /home/andreas/.ansible.cfg
configured module search path = Default w/o overrides
Ansible Configuration:
No changes to base configuration
Environment:
Ubuntu 14.04
Summary:
I'm running ansible against localhost. I want to use the
apt
core module to install some libraries. The task fails and gives an error message thatpython-apt
is not installed. But it is installed.Steps To Reproduce:
I'm running the following playbook using
ansible-playbook update_local.yml --ask-sudo-pass
Running
sudo apt-get install python-apt
givesExpected Results:
I expected the
python-boto
library to become installed.Actual Results: