Python-3.x – Installing corrupted packages using Ansible on Debian 11 Bullseye

3.x – Installing corrupted packages using Ansible on Debian 11 Bullseye… here is a solution to the problem.

3.x – Installing corrupted packages using Ansible on Debian 11 Bullseye

I want to install the Debian package (not yet) using Ansible 2.7.7 in Debian tests

I tried to perform this simple task :

  tasks:
  - name: install basic packages
    apt:
      name: ['mc', 'htop', 'strace','sudo','screen','lshw', 'postfix', 'etckeeper']
      state: present

But the installation fails with a strange message :

TASK [install basic packages] *********************************************************************************
fatal: [webserver.vitexsoftware.cz]: FAILED! => {"changed": false, "msg": "Could not import python modules: apt, apt_pkg. Please install python-apt package."}
        to retry, use: --limit @/home/vitex/Projects/VitexSoftware/Ansible/playbooks/orchestrate.retry

The Python package required for apt is installed as python3-apt

vitex@webserver:~/Projects/VitexSoftware/DockerTools$ aptitude search python | grep '\-apt'
i A python-apt-common - Python interface to libapt-pkg (locales)
p  python-apt-dev - Python interface to libapt-pkg (development files)
p  python-apt-doc - Python interface to libapt-pkg (API documentation)
i  python3-apt - Python 3 interface to libapt-pkg
p  python3-apt-dbg - Python 3 interface to libapt-pkg (debug extension)
v  python3-apt-dbg:any - 
v  python3-apt:any - 
p  python3-aptly - Aptly REST API client and useful tooling - Python 3.x
v  python3.9-apt - 
v  python3.9-apt-dbg - 
v  python3.9-apt-dbg:any - 
v  python3.9-apt:any - 

There is a closed Unresolved issue on GitHub: https://github.com/ansible/ansible/issues/73535 this won’t help me somehow.

How does it work like on Debian 10?

Solution

Specify python3 as the interpreter in the hosts file

[webservers]
webserver.vitexsoftware.cz ansible_host=10.11.56.210 ansible_python_interpreter=/bin/python3

Do its job :

TASK [install basic packages]  **************************************************************************************************************************************************************************************************************** ********************************
changed: [webserver.vitexsoftware.cz]

Related Problems and Solutions