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

6
.gitignore vendored Normal file
View File

@@ -0,0 +1,6 @@
*.log
*.pyc
**/__pycache__/
.env
.secrets

10
.gitlab-ci.yml Normal file
View File

@@ -0,0 +1,10 @@
---
stages:
- linter
linter:
stage: linter
image:
name: osshelp/drone-linter
entrypoint: [""]
script: [entrypoint.sh]

11
.yamllint Normal file
View File

@@ -0,0 +1,11 @@
extends: default
rules:
braces:
max-spaces-inside: 1
level: error
brackets:
max-spaces-inside: 1
level: error
line-length: disable
truthy: disable

11
README.md Normal file
View File

@@ -0,0 +1,11 @@
# helm-charts
Simple role for install helm charts
Usage:
```yaml
- role: helm-charts
when: inventory_hostname == groups["k8s-master"][0]
helm_charts:
- { values_files: ["helm-value/prometheus.yaml.j2", "files/helm-value/common.yml"], version: "25.1.0", namespace: prometheus, release: prometheus, repo_name: prometheus-community, chart_name: prometheus, repo_url: https://prometheus-community.github.io/helm-charts }
```

6
defaults/main.yml Normal file
View File

@@ -0,0 +1,6 @@
---
helm_binary_dir: "/usr/local/bin"
helm_force_update: false
helm_version: "v3.13.1"
helm_url: "https://get.helm.sh/helm-{{ k3s_helm_version }}-linux-amd64.tar.gz"

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('[]') }}"