Ansible K8s 模块:无法在 Python/usr/bin/python3 上导入所需的 Python 库 (openshift) [英] Ansible K8s module: Failed to import the required Python library (openshift) on Python /usr/bin/python3

查看:24
本文介绍了Ansible K8s 模块:无法在 Python/usr/bin/python3 上导入所需的 Python 库 (openshift)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

环境

Ansible 2.9.6 (python3)

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

出现以下错误

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"
}

这让我很困惑,

  • 根本原因是没有名为 kubernetes 的模块"?
  • 无法在 Python/usr/bin/python3 上导入所需的 Python 库 (openshift)"?

如何解决这个问题?

任何帮助将不胜感激!

顺便说一句,

Kubernetes 主节点有/usr/bin/python3

推荐答案

查看这里的文档:https://docs.ansible.com/ansible/latest/modules/k8s_module.html

似乎您需要:

  • python >= 2.7
  • openshift >= 0.6
  • PyYAML >= 3.11

一种方法是:

pip install openshift pyyaml kubernetes 

旁注,我在这里添加了 kubernetes,但我相信它是 openshift 的依赖项.

Side note, I've added kubernetes here but I believe it's a dependency of openshift.

我们也可以这样做:

pip3 install openshift pyyaml kubernetes --user

这篇关于Ansible K8s 模块:无法在 Python/usr/bin/python3 上导入所需的 Python 库 (openshift)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆