skip to Main Content

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 ?

2

Answers


  1. Chosen as BEST ANSWER

    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]
    

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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search