I am writing an Ansible playbook to build a Kubernetes cluster (K3S) running on 4 nodes with Raspi OS.
I am using the kubernetes.core package that can be installed in Ansible with the command:
ansible-galaxy collection install kubernetes.core
The API is found here.
I am trying to install the cert-manager
repository to Helm
with a task that is analogue to the command:
helm repo add jetstack https://charts.jetstack.io --force-update
And so far I have defined the task as:
- name: Add cert-manager Helm repository
kubernetes.core.helm_repository:
name: jetstack
url: https://charts.jetstack.io
force: true
But when I run my playbook I get the following error:
TASK [helm : Add cert-manager Helm repository]
***************************************************
An exception occurred during task execution. To see
the full traceback, use -vvv. The error was:
ModuleNotFoundError: No module named 'yaml'
Adding -vvv
gives a little more information, but still rather obscure:
The full traceback is:
Traceback (most recent call last):
File "/tmp/ansible_kubernetes.core.helm_repository_payload_tdbnu9cy/ansible_kubernetes.core.helm_repository_payload.zip/ansible_collections/kubernetes/core/plugins/modules/helm_repository.py", line 173, in <module>
ModuleNotFoundError: No module named 'yaml'
Is there anyone who knows what is going on?
Some modules in Ansible have external dependencies which you might need t installed them on either target node or controller node(This depends on where it will going to be used). To check module dependencies, by convention, they have REQUIREMENTS
field which you can check by using something like grep
or awk
:
ansible-doc kubernetes.core.helm_repository | awk '/REQUIREMENTS/,/^$/'
Example:
~> ansible-doc kubernetes.core.helm_repository | awk '/REQUIREMENTS/,/^$/'
REQUIREMENTS: helm (https://github.com/helm/helm/releases), yaml
(https://pypi.org/project/PyYAML/)
~> ansible-doc community.mysql.mysql_db | awk '/REQUIREMENTS/,/^$/'
REQUIREMENTS: MySQLdb (Python 2.x), PyMySQL (Python 2.7 and Python
3.x) or, mysql (command line binary),
mysqlclient (Python 3.5+) or, mysqldump
(command line binary)
keep in mind, not all of them always needed. for instance in mysql example its enough to have either of MySQLdb or PyMySQL. sometimes a dependency is used in a specific kind of task too. like mysqldump
would be used just if you want to create dumps using mysql Ansible module, otherwise you don't need it.