Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ansible - install python3-apt package

Using Ubuntu 18.04, Ansible 2.9, Python 3.6.9, have installed python3-apt

On a basic ansible command ansible -b all -m apt -a "name=apache2 state=latest" Get Error:

FAILED! => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    },
    "changed": false,
    "msg": "Could not import python modules: apt, apt_pkg. Please install python3-apt package."
}

$ sudo apt-get install python3-apt

$ ansible --version
ansible 2.9.12  
python version = 3.6.9

$ python --version
Python 3.7.6
like image 501
Sam-T Avatar asked Mar 07 '26 11:03

Sam-T


1 Answers

Go to python3 dist-package directory

cd /usr/lib/python3/dist-packages

And then link these two files

sudo ln -s apt_inst.cpython-35m-x86_64-linux-gnu.so apt_inst.so
sudo ln -s apt_pkg.cpython-35m-x86_64-linux-gnu.so apt_pkg.so
like image 84
Saravit Soeng Avatar answered Mar 08 '26 23:03

Saravit Soeng



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!