The env
Ansible 2.9.6 (python3)
Tried to run a simple playbook
- hosts: master
gather_facts: no
become: yes
tasks:
- name: create name space
k8s:
name: testing
api_version: v1
kind: Namespace
state: present
Getting following error
The full traceback is:
Traceback (most recent call last):
File "/tmp/ansible_k8s_payload_u121g92v/ansible_k8s_payload.zip/ansible/module_utils/k8s/common.py", line 33, in <module>
import kubernetes
ModuleNotFoundError: No module named 'kubernetes'
fatal: [192.168.20.38]: FAILED! => {
"changed": false,
"error": "No module named 'kubernetes'",
"invocation": {
"module_args": {
"api_key": null,
"api_version": "v1",
"append_hash": false,
"apply": false,
"ca_cert": null,
"client_cert": null,
"client_key": null,
"context": null,
"force": false,
"host": null,
"kind": "Namespace",
"kubeconfig": null,
"merge_type": null,
"name": "testing",
"namespace": null,
"password": null,
"proxy": null,
"resource_definition": null,
"src": null,
"state": "present",
"username": null,
"validate": null,
"validate_certs": null,
"wait": false,
"wait_condition": null,
"wait_sleep": 5,
"wait_timeout": 120
}
},
"msg": "Failed to import the required Python library (openshift) on k8smasternode'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"
}
It confuses me that,
- the root cause is "no module named kubernetes"?
- or "Failed to import the required Python library (openshift) on Python /usr/bin/python3"?
And how to fix that?
Any help would be appreciated!
btw,
Kubernetes master node has /usr/bin/python3
python --version
andansible --version | grep "python version"
and check if the versions are the same? There is similar issue on stackoverflow where community member fixed it withsudo pip install --upgrade --user openshift
, worth to try it. Additionally maybe this could work as workaround for that? Let me know if that help. – Viipuriopenshift
Python module dependency for the Ansiblek8s
module. – Televisionpython --version
is Python 2.7.17 ;ansible --version | grep "python version"
is python version = 3.6.9. Because there are 2 version Pythons are installed. is that an issue? (2) I've triedsudo pip install --upgrade --user openshift
but still same error (3) I haven't tried the workaround yet (cinhtau.net/2019/02/14/ansible-openshift-python)! – Paintingpip install openshift pyyaml kubernetes
andsudo pip install --upgrade --user openshift
– Paintingpython3 --version
should show you the version of python3 in use. also, on my example of this error, the error says the master node's name,k8smasternode
in your case. – Rainger