Initial commit

This commit is contained in:
2024-02-26 18:22:30 +03:00
commit 448035f50f
8 changed files with 137 additions and 0 deletions

47
tasks/charts.yml Normal file
View File

@@ -0,0 +1,47 @@
---
- name: Create var copied files
set_fact:
copied_files: []
- name: Generate values file from template
template:
src: "{{ item }}"
dest: "/tmp/{{ item | basename | regex_replace('.j2', '') }}"
loop: "{{ item.values_files|default([]) }}"
when: item is match('.*\.j2$')
register: template_action
- name: Copy yaml values
ansible.builtin.copy:
src: "{{ item }}"
dest: "/tmp/{{ item | basename }}"
loop: "{{ item.values_files|default('[]') }}"
when: not item is match('.*\.j2$')
register: copy_action
- name: Create list copied files with j2
set_fact:
copied_files: "{{ copied_files + ['/tmp/' + (item | basename | regex_replace('.j2', ''))] }}"
loop: "{{ item.values_files }}"
- name: Add Helm repository
community.kubernetes.helm_repository:
name: "{{ item.repo_name }}"
repo_url: "{{ item.repo_url }}"
state: present
- name: Install or upgrade Prometheus Helm chart
community.kubernetes.helm:
name: "{{ item.release }}"
chart_ref: "{{ item.repo_name }}/{{ item.chart_name }}"
release_namespace: "{{ item.namespace }}"
create_namespace: true
values_files: "{{ copied_files }}"
state: present
chart_version: "{{ item.version }}"
- name: Remove prometheus values file
file:
path: "{{ item }}"
state: absent
loop: "{{ copied_files }}"

33
tasks/install.yml Normal file
View File

@@ -0,0 +1,33 @@
---
- name: Download helm
get_url:
url: "{{ k3s_helm_url }}"
dest: "/tmp/helm-{{ k3s_helm_version }}.tar.gz"
when: ansible_facts.architecture == "x86_64"
- name: Create a directory to unpack Helm
tempfile:
state: directory
register: helm_unpack_directory
- name: Unpack Helm tarball
unarchive:
src: "/tmp/helm-{{ k3s_helm_version }}.tar.gz"
remote_src: yes
dest: "{{ helm_unpack_directory.path }}"
- name: Move Helm to the desired installation directory
copy:
src: "{{ helm_unpack_directory.path }}/linux-amd64/helm"
dest: "{{ k3s_binary_dir }}/helm"
remote_src: yes
mode: '0755'
when: ansible_facts.architecture == "x86_64"
- name: Clean up downloaded and unpacked files
file:
path: "{{ item }}"
state: absent
with_items:
- "/tmp/helm-{{ k3s_helm_version }}.tar.gz"
- "{{ helm_unpack_directory.path }}"

13
tasks/main.yml Normal file
View File

@@ -0,0 +1,13 @@
---
- name: check if binary helm already exists
stat:
path: "{{ helm_binary_dir }}/helm"
register: binary_helm_check_result
- name: install binary helm
include_tasks: installation.yml
when: not helm.stat.exists or helm_force_update
- name: Install charts
include_tasks: charts.yml
loop: "{{ helm_charts|default('[]') }}"