Hosts File
First we need to create a hosts file to let Ansible
access the Kubernetes node machines.
For Kubernetes nodes the hosts
file is as the following …
[masters]
master ansible_host=192.168.1.20 ansible_port=622 ansible_user=kube-admin ansible_password=****** ansible_sudo_pass=******
[workers]
worker1 ansible_host=192.168.1.21 ansible_port=622 ansible_user=kube-admin ansible_password=****** ansible_sudo_pass=******
For installing the helm chart you may do not need to workers node group and
ansible_sudo_pass
parameters. So if you want to only add helm installation you can remove those.
Ansible Kubernetes collection installation
To enable your system to run Kubernetes Ansible commands you need to install Kubernetes ansible collection first, using below command.
ansible-galaxy collection install kubernetes.core
Config File
Then we need create a file in Ansible
project with .yaml
file extension.
- hosts: master
become: yes
tasks:
- name: Add <example> Helm repo
become: yes
become_user: <kube-admin>
kubernetes.core.helm_repository:
name: <example-repo>
repo_url: <https://example.helm.chart.repo>
- name: Install <Example>
become: yes
become_user: <kube-admin>
kubernetes.core.helm:
name: <example-release-name>
chart_ref: <example-repo>/<example-chart>
chart_version: <0.0.1>
release_namespace: <example-namespace>
update_repo_cache: true
values:
ingress:
enabled: true
Consider that we should replace all code part inside
<>
characters. And also override the value properties.
And finally we run ansible-playbook -i hosts <file-path/file-name.yaml>
with replace our relative file path inside <>
.