Could not import python modules: apt, apt_pkg Ansible playbook error
Could not import python modules: apt, apt_pkg Ansible playbook error
I am trying to install apache2 on my slave machine using an ansible playbook. But the below error is thrown in the installation task.
TASK [Install Apache 2] ******************************************************** [WARNING]: Updating cache and auto-installing missing dependency: python3-apt fatal: [testserver]: FAILED! => {"changed": false, "msg": "Could not import python modules: apt, apt_pkg. Please install python3-apt package."}
python3 is already installed in the target machine. In the controller machine, ansible 2.9.17 is installed. How to resolve this ?
vito Selected answer as best September 21, 2021
Ansible is not pointing to the python3 module in your target machine. You will have to provide the ansible python interpreter path in the playbook using ansible vars module.
- hosts: testserver become: true vars: ansible_python_interpreter: "/usr/bin/python3"
vito Selected answer as best September 21, 2021