feat: always delete custom- prefixed files from k3s_server_manifests_dir

Signed-off-by: Devin Buhl <devin@buhl.casa>
This commit is contained in:
Devin Buhl committed 2023-05-27 08:21:29 -04:00
1 parent 99e4ffec26
commit 00798e85e8
2 files changed
+33 -47

No files matched your search

@@ -34,27 +34,13 @@ k3s_server_manifests_urls:
# Tigera Operator
- url: https://raw.githubusercontent.com/projectcalico/calico/v3.25.1/manifests/tigera-operator.yaml
filename: custom-calico-tigera-operator.yaml
# Prometheus Operator
- url: https://raw.githubusercontent.com/prometheus-operator/prometheus-operator/v0.65.1/example/prometheus-operator-crd/monitoring.coreos.com_alertmanagerconfigs.yaml
filename: custom-prometheus-alertmanagerconfigs.yaml
- url: https://raw.githubusercontent.com/prometheus-operator/prometheus-operator/v0.65.1/example/prometheus-operator-crd/monitoring.coreos.com_alertmanagers.yaml
filename: custom-prometheus-alertmanagers.yaml
# Essential Prometheus Operator CRDs
- url: https://raw.githubusercontent.com/prometheus-operator/prometheus-operator/v0.65.1/example/prometheus-operator-crd/monitoring.coreos.com_podmonitors.yaml
filename: custom-prometheus-podmonitors.yaml
- url: https://raw.githubusercontent.com/prometheus-operator/prometheus-operator/v0.65.1/example/prometheus-operator-crd/monitoring.coreos.com_probes.yaml
filename: custom-prometheus-probes.yaml
- url: https://raw.githubusercontent.com/prometheus-operator/prometheus-operator/v0.65.1/example/prometheus-operator-crd/monitoring.coreos.com_prometheuses.yaml
filename: custom-prometheus-prometheuses.yaml
- url: https://raw.githubusercontent.com/prometheus-operator/prometheus-operator/v0.65.1/example/prometheus-operator-crd/monitoring.coreos.com_prometheusrules.yaml
filename: custom-prometheus-prometheusrules.yaml
- url: https://raw.githubusercontent.com/prometheus-operator/prometheus-operator/v0.65.1/example/prometheus-operator-crd/monitoring.coreos.com_servicemonitors.yaml
filename: custom-prometheus-servicemonitors.yaml
- url: https://raw.githubusercontent.com/prometheus-operator/prometheus-operator/v0.65.1/example/prometheus-operator-crd/monitoring.coreos.com_thanosrulers.yaml
filename: custom-prometheus-thanosrulers.yaml
- url: https://raw.githubusercontent.com/prometheus-operator/prometheus-operator/v0.65.1/example/prometheus-operator-crd/monitoring.coreos.com_scrapeconfigs.yaml
filename: custom-prometheus-scrapeconfigs.yaml
- url: https://raw.githubusercontent.com/prometheus-operator/prometheus-operator/v0.65.1/example/prometheus-operator-crd/monitoring.coreos.com_prometheusagents.yaml
filename: custom-prometheus-prometheusagents.yaml
# (list) A flat list of templates to deploy on the primary control plane
# /var/lib/rancher/k3s/server/manifests
+32 -32
View File
@@ -10,6 +10,18 @@
ansible.builtin.pause:
seconds: 5
tasks:
- name: Check if cluster is installed
ansible.builtin.stat:
path: /etc/rancher/k3s/config.yaml
register: k3s_check_installed
check_mode: false
- name: Ignore manifests templates and urls if the cluster is already installed
ansible.builtin.set_fact:
k3s_server_manifests_templates: []
k3s_server_manifests_urls: []
when: k3s_check_installed.stat.exists
- name: Install Kubernetes
ansible.builtin.include_role:
name: xanmanning.k3s
@@ -56,34 +68,20 @@
wait_sleep: 10
wait_timeout: 360
loop:
- kind: Deployment
name: tigera-operator
- name: tigera-operator
kind: Deployment
namespace: tigera-operator
- kind: DaemonSet
name: kube-vip
- name: kube-vip
kind: DaemonSet
namespace: kube-system
- kind: Installation
name: default
- kind: CustomResourceDefinition
name: alertmanagerconfigs.monitoring.coreos.com
- kind: CustomResourceDefinition
name: alertmanagers.monitoring.coreos.com
- kind: CustomResourceDefinition
name: podmonitors.monitoring.coreos.com
- kind: CustomResourceDefinition
name: probes.monitoring.coreos.com
- kind: CustomResourceDefinition
name: prometheuses.monitoring.coreos.com
- kind: CustomResourceDefinition
name: prometheusrules.monitoring.coreos.com
- kind: CustomResourceDefinition
name: servicemonitors.monitoring.coreos.com
- kind: CustomResourceDefinition
name: thanosrulers.monitoring.coreos.com
- kind: CustomResourceDefinition
name: scrapeconfigs.monitoring.coreos.com
- kind: CustomResourceDefinition
name: prometheusagents.monitoring.coreos.com
- name: podmonitors.monitoring.coreos.com
kind: CustomResourceDefinition
- name: prometheusrules.monitoring.coreos.com
kind: CustomResourceDefinition
- name: servicemonitors.monitoring.coreos.com
kind: CustomResourceDefinition
when:
- k3s_server_manifests_templates | length > 0
or k3s_server_manifests_urls | length > 0
@@ -95,14 +93,16 @@
# is needed because k3s has an awesome "feature" to always re-deploy them when the k3s
# service is restarted. Removing them does not uninstall the manifests from your cluster.
- name: Remove deployed manifest templates
ansible.builtin.file:
path: "{{ k3s_server_manifests_dir }}/{{ item | basename | regex_replace('\\.j2$', '') }}"
state: absent
loop: "{{ k3s_server_manifests_templates | default([]) }}"
- name: Get a list of all custom manifest files
ansible.builtin.find:
paths: "{{ k3s_server_manifests_dir }}"
file_type: file
use_regex: true
patterns: ["^custom-.*"]
register: custom_manifest_files
- name: Remove deployed manifest urls
- name: Delete all custom manifest files
ansible.builtin.file:
path: "{{ k3s_server_manifests_dir }}/{{ item.filename }}"
path: "{{ item.path }}"
state: absent
loop: "{{ k3s_server_manifests_urls | default([]) }}"
loop: "{{ custom_manifest_files }}"