0

An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ModuleNotFoundError: No module named 'kubernetes'

failed: [ubuntu] (item={'name': 'deploymentnginx.yaml.j2'}) => {"ansible_loop_var": "item", "changed": false, "error": "No module named 'kubernetes'", "item": {"name": "deploymentnginx.yaml.j2"}, "msg": "Failed to import the required Python library (openshift) on ubuntu's Python /usr/bin/python3. Please read module documentation and install in the appropriate location. If the required library is installed, but Ansible is using the wrong Python interpreter, please consult the documentation on ansible_python_interpreter"}

Kubernetes is installed but still getting error

(molecule-venv) root@picklock1:~/molecule-blog/mywebapp# pip list -o
Package    Version Latest  Type
---------- ------- ------- -----
ansible    2.9.0   4.9.0   sdist
Cerberus   1.3.2   1.3.4   sdist
kubernetes 12.0.0  19.15.0 wheel
pip        20.0.2  21.3.1  wheel
PyYAML     5.4.1   6.0     wheel
setuptools 44.0.0  59.4.0  wheel
Harsh Manvar
  • 27,020
  • 6
  • 48
  • 102
  • 1
    _Failed to import the required Python library (openshift) on ubuntu's Python /usr/bin/python3. Please read module documentation and install in the appropriate location. If the required library is installed, but Ansible is using the wrong Python interpreter, please consult the documentation on ansible_python_interpreter_ – β.εηοιτ.βε Nov 29 '21 at 23:44

1 Answers1

0

In my case I had interpreter_python = auto_silent (default) in ansible.cfg which was trying the /usr/bin/python (OS-wide) where I did not have the kubernetes module installed as I am using venv (python's virtual environment) to keep the OS uncluttered.

The solution was setting it to "python" (the full-path works too) in the ansible.cfg:

interpreter_python = python

Andrey Arapov
  • 101
  • 1
  • 2