Skip to content

Commit

Permalink
chore: fix
Browse files Browse the repository at this point in the history
  • Loading branch information
kashalls committed Jun 10, 2023
1 parent 8b2c147 commit cbcd1c1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
4 changes: 2 additions & 2 deletions ansible/inventory/group_vars/master/k3s.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ k3s_server:
disable-kube-proxy: true
write-kubeconfig-mode: "644"
# Network CIDR to use for pod IPs
cluster-cidr: "10.42.0.0/16"
cluster-cidr: "{{ cluster_cidr }}"
# Network CIDR to use for service IPs
service-cidr: "10.43.0.0/16"
service-cidr: "{{ service_cidr }}"
kube-controller-manager-arg:
# Required to monitor kube-controller-manager with kube-prometheus-stack
- "bind-address=0.0.0.0"
Expand Down
31 changes: 22 additions & 9 deletions ansible/playbooks/cluster-installation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -104,19 +116,20 @@
namespace: kube-system
state: absent

# NOTE
# Cleaning up certain manifests from the /var/lib/rancher/k3s/server/manifests directory
# 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

- 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 }}"

0 comments on commit cbcd1c1

Please sign in to comment.