-1

I'm running Ansible on macOS 12.4 and I have following task which uses kubernetes.core.k8s module.

- name: "apply {{ downloaded_metallb_manifest }}"
  kubernetes.core.k8s:
    src: "{{ downloaded_metallb_manifest }}"
    state: present
    wait: yes

I installed the collection as per documentation - https://docs.ansible.com/ansible/latest/collections/kubernetes/core/k8s_module.html

% ansible-galaxy collection install kubernetes.core               
Starting galaxy collection install process
Process install dependency map
Starting collection install process
Downloading https://galaxy.ansible.com/download/kubernetes-core-2.3.2.tar.gz to /Users/grit/.ansible/tmp/ansible-local-811952kgpja6g/tmpc_mrql42/kubernetes-core-2.3.2-c3aeycar
Installing 'kubernetes.core:2.3.2' to '/Users/grit/.ansible/collections/ansible_collections/kubernetes/core'
kubernetes.core:2.3.2 was installed successfully

However, the task still fails.

TASK [metallb : apply /tmp/metallb-native.yaml] ****************************************************************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ModuleNotFoundError: No module named 'kubernetes'
fatal: [node1.local]: FAILED! => {"changed": false, "error": "No module named 'kubernetes'", "msg": "Failed to import the required Python library (kubernetes) on node1'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"}

Running the playbook with explicit -e 'ansible_python_interpreter=/usr/bin/python3' doesn't make any difference.

What went wrong here?

Here is Ansible version.

ansible [core 2.13.1]
  config file = None
  configured module search path = ['/Users/user/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/Cellar/ansible/6.1.0/libexec/lib/python3.10/site-packages/ansible
  ansible collection location = /Users/user/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/local/bin/ansible
  python version = 3.10.5 (main, Jun 23 2022, 17:15:25) [Clang 13.1.6 (clang-1316.0.21.2.5)]
  jinja version = 3.1.2
  libyaml = True

The kubernetes collection is in the ansible collection location

% ls -l /Users/user/.ansible/collections/ansible_collections 
total 0
drwxr-xr-x  3 user  staff  96 26 Aug 12:57 kubernetes
drwxr-xr-x  3 user  staff  96 26 Aug 12:57 kubernetes.core-2.3.2.info

Following prerequisites have been installed as well.

% pip3 list | egrep -i 'kubernetes|pyyaml|jsonpatch'
jsonpatch           1.32
kubernetes          24.2.0
PyYAML              6.0
learnd
  • 77
  • 5
  • 1
    https://docs.ansible.com/ansible/latest/collections/kubernetes/core/k8s_module.html#requirements => `pip install kubernetes` – Zeitounator Aug 26 '22 at 12:33
  • yeah those have been installed as well, just updated the question. – learnd Aug 26 '22 at 13:12
  • 1
    Please use the internal search engine at top of this page and you'll find that such questions have been asked by dozens. The possible underlying problems are always the same and can be: 1) the library is not installed at all 2) the library is installed in the wrong version of python 3) the library has been installed on the controller whereas it is expected to be present on the target (or vice versa). 4) some mix of all these. To be clear, in the above case the library should be installed on `node1.local` in the python version used by Ansible on the target (rephrasing the error message...) – Zeitounator Aug 26 '22 at 13:16
  • Thank you! My bad I was assuming everything must be installed on the controller. Fixed now – learnd Aug 26 '22 at 17:41

1 Answers1

0

This is sorted by installing these libraries on target machine via pip3.

jsonpatch           1.32
kubernetes          24.2.0
PyYAML              6.0
learnd
  • 77
  • 5