【发布时间】:2022-07-22 05:40:40
【问题描述】:
我收到此错误:
错误!无法解析模块/操作“kubernetes.core.k8s”。这通常表示拼写错误、缺少集合或模块路径不正确。
但是,我以为我安装了它,看起来它已经安装了:
[me@server ansible]$ ansible-galaxy collection install kubernetes.core
Process install dependency map
Starting collection install process
Skipping 'kubernetes.core' as it is already installed
配置是
[user@server ~]$ ansible --version
ansible 2.9.25
config file = /etc/ansible/ansible.cfg
configured module search path = ['/home/user/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3.6/site-packages/ansible
executable location = /usr/bin/ansible
python version = 3.6.8 (default, Mar 18 2021, 08:58:41) [GCC 8.4.1 20200928 (Red Hat 8.4.1-1)]
比我尝试在root 用户下安装和在运行 Ansible 的用户下安装,发现它确实安装了,但现在出现此错误:
The full traceback is:
Traceback (most recent call last):
File "/tmp/ansible_kubernetes.core.k8s_payload_yikI_F/ansible_kubernetes.core.k8s_payload.zip/ansible_collections/kubernetes/core/plugins/module_utils/common.py", line 92, in <module>
from kubernetes.dynamic.resource import ResourceInstance
ImportError: No module named kubernetes.dynamic.resource
fatal: [1.2.3.4]: FAILED! => {
"changed": false,
"error": "No module named kubernetes.dynamic.resource",
"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,
"continue_on_error": false,
"delete_options": null,
"force": false,
"host": null,
"kind": null,
"kubeconfig": null,
"label_selectors": null,
"merge_type": null,
"name": null,
"namespace": null,
"password": null,
"persist_config": null,
"proxy": null,
"proxy_headers": null,
"resource_definition": null,
"src": "/home/maasfsr/AnsibleClone/deployments/develop/k8s/neo4j-bolt-pv.yaml",
"state": "present",
"template": null,
"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 (kubernetes) on K8S-Master's Python /usr/bin/python. 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"
}
这是我应该发布或相关的不同问题吗?
【问题讨论】:
-
你的ansible版本是什么?
ansible --version -
如错误消息中所述,它可能是由
incorrect module path引起的。根据您的环境和ansible.cfg,您的集合可能安装在用户me和路径~/.ansible/collections/ansible_collections/community/下,从而您的Ansible 控制器在其他东西下运行或执行。您可以在root下测试执行ansible-galaxy collection install community.kubernetes -p /usr/share/ansible/collections/ansible_collections/并再次测试。 -
[user@server ~]$ ansible --version ansible 2.9.25 配置文件 = /etc/ansible/ansible.cfg 配置模块搜索路径 = ['/home/user/.ansible/plugins /modules', '/usr/share/ansible/plugins/modules'] ansible python 模块位置 = /usr/lib/python3.6/site-packages/ansible 可执行位置 = /usr/bin/ansible python 版本 = 3.6。 8(默认,2021 年 3 月 18 日,08:58:41)[GCC 8.4.1 20200928 (Red Hat 8.4.1-1)]
-
我在应该运行的用户下运行 ansible-galaxy collection install community.kubernetes 并安装它,但后来我得到了:
-
根据Installation and Usage 的说明,您还需要安装Python Kubernetes 库才能使用该集合。
标签: kubernetes ansible ansible-module