python
python copied to clipboard
Missing module: kubernetes.dynamic
What happened (please include outputs or screenshots):
I have an Ansible playbook that is being used to make changes to a live Kubernetes cluster. I do not have Ansible installed on any cluster nodes. Instead, I run an Ansible Docker image and pass it the necessary arguments and configuration for it to operate on nodes in the cluster.
Some of the playbook tasks use the kubernetes
Python module to collect information and make changes. This necessitated that I install some missing software - pip
and the kubernetes
module. When I run the playbook, I'm getting an error that indicates that something is missing:
ModuleNotFoundError: No module named 'kubernetes.dynamic'
The full error:
The full traceback is:
Traceback (most recent call last):
File "/tmp/ansible_kubernetes.core.k8s_info_payload_gkc1e8y4/ansible_kubernetes.core.k8s_info_payload.zip/ansible_collections/kubernetes/core/plugins/module_utils/common.py", line 122, in <module>
from kubernetes.dynamic.resource import ResourceInstance
ModuleNotFoundError: No module named 'kubernetes.dynamic'
fatal: [arc-master-1]: FAILED! => {
"changed": false,
"error": "No module named 'kubernetes.dynamic'",
"invocation": {
"module_args": {
"api_key": null,
"api_version": "v1",
"ca_cert": null,
"client_cert": null,
"client_key": null,
"context": null,
"field_selectors": [],
"host": null,
"impersonate_groups": null,
"impersonate_user": null,
"kind": "ConfigMap",
"kubeconfig": "/home/master/.kube/config",
"label_selectors": [],
"name": "kube-proxy",
"namespace": "kube-system",
"no_proxy": null,
"password": null,
"persist_config": null,
"proxy": null,
"proxy_headers": null,
"username": null,
"validate_certs": null,
"wait": false,
"wait_condition": null,
"wait_sleep": 5,
"wait_timeout": 120
}
},
"msg": "Failed to import the required Python library (kubernetes) on arc-master-1's Python /usr/bin/python3. Please read the module documentation and install it 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"
}
What you expected to happen: The playbook to execute without errors, modifying the Kubernetes cluster configuration as expected.
How to reproduce it (as minimally and precisely as possible):
Execute the docker run
command described below.
Anything else we need to know?: The docker run command:
$ docker run --rm -it -e ANSIBLE_CONFIG=/data/ansible.cfg -e K8S_AUTH_KUBECONFIG=/home/master/.kube/config -v "C:\Users\jgagnon\devops\ansible":/data cytopia/ansible:latest-tools ansible-playbook /data/playbook-arc-prometheus.yaml
Tasks from the playbook:
- name: "Install pip"
become: true
ansible.builtin.shell:
cmd: "apt-get update && apt-get install -y python3-pip"
- name: "Install kubernetes Python module"
become: true
ansible.builtin.pip:
name:
kubernetes
- name: "Get kube-proxy ConfigMap"
kubernetes.core.k8s_info:
kind: ConfigMap
name: kube-proxy
namespace: kube-system
kubeconfig: "{{ lookup('env', 'K8S_AUTH_KUBECONFIG') }}"
register: kube_proxy_data
Execution of the third task results in the errors described. Initially, without the first two tasks, the playbook would fail because the kubernetes module was not installed.
If there is other system or configuration information that would be useful, please let me know and I will try to provide it.
Docker container information:
$ python3 --version
Python 3.10.9
$ pip3 --version
pip 22.1.1 from /usr/lib/python3.10/site-packages/pip (python 3.10)
$ pip3 list
Package Version
-------------- -------
ansible 7.1.0
ansible-core 2.14.1
appdirs 1.4.4
bcrypt 4.0.1
cffi 1.15.1
contextlib2 21.6.0
cryptography 39.0.0
dnspython 2.2.1
Jinja2 3.1.2
jmespath 1.0.1
junit-xml 1.9
lxml 4.9.2
MarkupSafe 2.1.1
mitogen 0.3.3
more-itertools 8.13.0
ordered-set 4.0.2
packaging 21.3
paramiko 2.12.0
pep517 0.12.0
pip 22.1.1
pycparser 2.21
PyNaCl 1.5.0
pyparsing 2.4.7
PyYAML 6.0
resolvelib 0.8.1
retrying 1.3.3
setuptools 59.4.0
six 1.16.0
tomli 2.0.1
$ ansible --version
ansible [core 2.14.1]
config file = /data/ansible.cfg
configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3.10/site-packages/ansible
ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/bin/ansible
python version = 3.10.9 (main, Dec 10 2022, 13:54:12) [GCC 11.2.1 20220219] (/usr/bin/python3)
jinja version = 3.1.2
libyaml = True
Environment:
- Kubernetes version (
kubectl version
):
WARNING: This version information is deprecated and will be replaced with the output from kubectl version --short. Use --output=yaml|json to get the full version.
Client Version: version.Info{Major:"1", Minor:"24", GitVersion:"v1.24.2", GitCommit:"f66044f4361b9f1f96f0053dd46cb7dce5e990a8", GitTreeState:"clean", BuildDate:"2022-06-15T14:22:29Z", GoVersion:"go1.18.3", Compiler:"gc", Platform:"windows/amd64"}
Kustomize Version: v4.5.4
Server Version: version.Info{Major:"1", Minor:"24", GitVersion:"v1.24.9", GitCommit:"9710807c82740b9799453677c977758becf0acbb", GitTreeState:"clean", BuildDate:"2022-12-08T10:08:06Z", GoVersion:"go1.18.9", Compiler:"gc", Platform:"linux/amd64"}
- OS (e.g., MacOS 10.13.6):
Ubuntu 20.04.5 LTS (GNU/Linux 5.4.0-136-generic x86_64)
- Python version (
python --version
)
Python 3.8.10
- Pip version (
pip --version
)
pip 20.0.2 from /usr/lib/python3/dist-packages/pip (python 3.8)
- Python client version (
pip list | grep kubernetes
)
$ pip show kubernetes
Name: kubernetes
Version: 25.3.0
Summary: Kubernetes python client
Home-page: https://github.com/kubernetes-client/python
Author: Kubernetes
Author-email:
License: Apache License Version 2.0
Location: /usr/local/lib/python3.8/dist-packages
Requires: certifi, requests-oauthlib, urllib3, requests, pyyaml, google-auth, python-dateutil, setuptools, six, websocket-client
Required-by:
/assign @fabianvf
The Kubernetes project currently lacks enough contributors to adequately respond to all issues.
This bot triages un-triaged issues according to the following rules:
- After 90d of inactivity,
lifecycle/stale
is applied - After 30d of inactivity since
lifecycle/stale
was applied,lifecycle/rotten
is applied - After 30d of inactivity since
lifecycle/rotten
was applied, the issue is closed
You can:
- Mark this issue as fresh with
/remove-lifecycle stale
- Close this issue with
/close
- Offer to help out with Issue Triage
Please send feedback to sig-contributor-experience at kubernetes/community.
/lifecycle stale
/remove-lifecycle stale
Is anyone going to work on this sometime in the foreseeable future?
Have you tried updating the version of k8s?
The Kubernetes project currently lacks enough contributors to adequately respond to all issues.
This bot triages un-triaged issues according to the following rules:
- After 90d of inactivity,
lifecycle/stale
is applied - After 30d of inactivity since
lifecycle/stale
was applied,lifecycle/rotten
is applied - After 30d of inactivity since
lifecycle/rotten
was applied, the issue is closed
You can:
- Mark this issue as fresh with
/remove-lifecycle stale
- Close this issue with
/close
- Offer to help out with Issue Triage
Please send feedback to sig-contributor-experience at kubernetes/community.
/lifecycle stale
The Kubernetes project currently lacks enough active contributors to adequately respond to all issues.
This bot triages un-triaged issues according to the following rules:
- After 90d of inactivity,
lifecycle/stale
is applied - After 30d of inactivity since
lifecycle/stale
was applied,lifecycle/rotten
is applied - After 30d of inactivity since
lifecycle/rotten
was applied, the issue is closed
You can:
- Mark this issue as fresh with
/remove-lifecycle rotten
- Close this issue with
/close
- Offer to help out with Issue Triage
Please send feedback to sig-contributor-experience at kubernetes/community.
/lifecycle rotten
The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.
This bot triages issues according to the following rules:
- After 90d of inactivity,
lifecycle/stale
is applied - After 30d of inactivity since
lifecycle/stale
was applied,lifecycle/rotten
is applied - After 30d of inactivity since
lifecycle/rotten
was applied, the issue is closed
You can:
- Reopen this issue with
/reopen
- Mark this issue as fresh with
/remove-lifecycle rotten
- Offer to help out with Issue Triage
Please send feedback to sig-contributor-experience at kubernetes/community.
/close not-planned
@k8s-triage-robot: Closing this issue, marking it as "Not Planned".
In response to this:
The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.
This bot triages issues according to the following rules:
- After 90d of inactivity,
lifecycle/stale
is applied- After 30d of inactivity since
lifecycle/stale
was applied,lifecycle/rotten
is applied- After 30d of inactivity since
lifecycle/rotten
was applied, the issue is closedYou can:
- Reopen this issue with
/reopen
- Mark this issue as fresh with
/remove-lifecycle rotten
- Offer to help out with Issue Triage
Please send feedback to sig-contributor-experience at kubernetes/community.
/close not-planned
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.