3

I woud like to install debian packages using Ansible 2.7.7 on Debian testing (yet)

I try to execute this simple task:

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


But the installation is failing with 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 requied python package 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 an closed unresolved issue on github: https://github.com/ansible/ansible/issues/73535 which wont help me somehow.

How to make working as on Debian 10 ?

Cybervitexus
  • 291
  • 4
  • 19
  • 1
    Check `ansible_python` on the remote to make sure you are using the installation you think you are and eventually set `ansible_python_interpreter` for that host to the correct version holding the module (or install it with pip in the other version...). For more info, check the doc on [interpreter discovery](https://docs.ansible.com/ansible/latest/reference_appendices/interpreter_discovery.html) – Zeitounator May 29 '21 at 09:59
  • `[webservers] webserver.vitexsoftware.cz ansible_host=10.11.56.210 ansible_python_interpreter=/bin/python3` Help me to install packages. – Cybervitexus May 29 '21 at 10:31

2 Answers2

3

Specification of python3 as interpreter in hosts file

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

Make its job:

TASK [install basic packages] ************************************************************************************************************************************************************************************************************************************************
changed: [webserver.vitexsoftware.cz]
Cybervitexus
  • 291
  • 4
  • 19
  • 1
    Does anyone know why this is necessary? I don't mean that as a passive aggressive jab, I just literally mean why do you have to specify python3? `python --version` shows 2.7.18 on a fresh Debian Stable ("Bullseye") install, and indeed there is no 'python-apt' package, but there is a 'python-apt-common'? Your suggestion works, thank you @cybervitexus! – Jeff Welling Oct 17 '21 at 20:31
  • Not every system is fresh. Some systems began years ago as debian 8 with default python 2. The python-apt become from Ubuntu world and you can install it on debian machine using pip command: https://pypi.org/project/python-apt/ – Cybervitexus Oct 20 '21 at 06:46
0

The other option that worked for me is to just remove python2 from the target host.

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jan 11 '22 at 03:56
  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/30786104) – Ghost Ops Jan 14 '22 at 08:26