I've create the following task in my ansible playbook.
- name: Create a k8s namespace
k8s:
state: present
definition:
apiVersion: v1
kind: Secret
metadata:
name: bigip-login
namespace: kube-system
data:
password: dGVzdA==
username: YWRtaW4=
type: Opaque
However when I run my playbook I got the following error:
The full traceback is:
Traceback (most recent call last):
File "/tmp/ansible_k8s_payload_n071fcyu/ansible_k8s_payload.zip/ansible_collections/kubernetes/core/plugins/module_utils/common.py", line 92, in <module>
from kubernetes.dynamic.resource import ResourceInstance
ModuleNotFoundError: No module named 'kubernetes'
fatal: [master.madebeen.com]: 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,
"continue_on_error": false,
"definition": {
"apiVersion": "v1",
"data": {
"password": "VGFyLk1pZC5GdW4tNDU2",
"username": "YWRtaW4="
},
"kind": "Secret",
"metadata": {
"name": "bigip-login",
"namespace": "kube-system"
},
"type": "Opaque"
},
"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": {
"apiVersion": "v1",
"data": {
"password": "VGFyLk1pZC5GdW4tNDU2",
"username": "YWRtaW4="
},
"kind": "Secret",
"metadata": {
"name": "bigip-login",
"namespace": "kube-system"
},
"type": "Opaque"
},
"src": null,
"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 master'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"
According to the example provided here that should've worked. I have also tried the following suggested (without any success) due to not having the json file provided here as an example:
---
apiVersion: v1
data:
password: dGVzdA==
username: YWRtaW4=
kind: Secret
metadata:
name: bigip-login
namespace: kube-system
type: Opaque
What intrigues me is the fact that both community/core kubernetes versions are currently installed:
marlon@ansible:~/.ansible$ ansible-galaxy collection install community.kubernetes
Process install dependency map
Starting collection install process
Skipping 'community.kubernetes' as it is already installed
marlon@ansible:~/.ansible$ ansible-galaxy collection install kubernetes.core
Process install dependency map
Starting collection install process
Skipping 'kubernetes.core' as it is already installed
marlon@ansible:~/.ansible$
Here is my python version that ansible is currently using:
marlon@ansible:~$ python3 --version
Python 3.8.10
marlon@ansible:~$ ansible --version | grep "python version"
python version = 3.8.10 (default, Sep 28 2021, 16:10:42) [GCC 9.3.0]
marlon@ansible:~$
Installed ubuntu like recommended on ansible installation file:
$ sudo apt update
$ sudo apt install software-properties-common
$ sudo add-apt-repository --yes --update ppa:ansible/ansible
$ sudo apt install ansible
Do you have any suggestions for use cases 1 and 2 so we can once and for all leave it here for future reference for others to benefit from them?