3

I get this error:

ERROR! couldn't resolve module/action 'kubernetes.core.k8s'. This often indicates a misspelling, missing collection, or incorrect module path.

However, I thought I installed it and looks like it is installed:

[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

The configuration is

[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)]

Than I've tried installing under the root user and under the user I'm running Ansible as and found it did install, but now got this error:

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

Is this a different question I should post or related?

  • 2
    What is your ansible version? `ansible --version` – β.εηοιτ.βε Jan 06 '22 at 22:57
  • As stated in the error message it might be caused by an `incorrect module path`. Depending on your environment and `ansible.cfg`, your collections may be installed under user `me` and path `~/.ansible/collections/ansible_collections/community/`, whereby your Ansible controller is running or executed under something else. You could test under `root` to perform `ansible-galaxy collection install community.kubernetes -p /usr/share/ansible/collections/ansible_collections/` and test again. – U880D Jan 07 '22 at 09:03
  • [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)] – Benjamin W Larson Jan 07 '22 at 16:04
  • I ran ansible-galaxy collection install community.kubernetes under the user that should be running and it installed it, but then I got: – Benjamin W Larson Jan 07 '22 at 16:12
  • 2
    According the [Installation and Usage](https://galaxy.ansible.com/kubernetes/core) instructions you need to install the [Python Kubernetes](https://pypi.org/project/kubernetes/) library too to use the collection. – U880D Jan 07 '22 at 16:44
  • I did - pip3 install kubernetes (I don't have pip) and it confirmed it was installed. – Benjamin W Larson Jan 10 '22 at 21:02
  • @BenjaminWLarson, also the installation via `pip3 install kubernetes` will do it under a specific user and install into a specific path. Without the full information of all involved users and paths and with the given error message `ImportError: No module named kubernetes.dynamic.resource`, it seems that the installation is still not fully done. – U880D Jan 11 '22 at 09:40
  • @BenjaminWLarson, however, if you have according `pip3 install ...`, `pip3` and `python3` only, you may try to introduce a `ln -s /usr/bin/python3 /usr/bin/python` also. Furthermore it might be necessary to start [Debugging](https://docs.ansible.com/ansible/latest/dev_guide/debugging.html) of modules. – U880D Jan 11 '22 at 09:45

1 Answers1

1

Although you can follow this answer: https://stackoverflow.com/a/60867449/5508998

I found that it only worked when you install those packages using sudo, so

sudo pip install openshift pyyaml kubernetes 
StvnSpnz
  • 293
  • 4
  • 11