fix(ansible): only run certain tasks on k3s_primary_control_node

Signed-off-by: Devin Buhl <devin@buhl.casa>
This commit is contained in:
Devin Buhl committed 2023-06-17 07:48:59 -04:00
1 parent de7a73f0ec
commit 746f49e028
1 file changed
+30 -36
+30 -36
View File
@@ -11,16 +11,16 @@
seconds: 5
tasks:
- name: Check if cluster is installed
check_mode: false
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
when: k3s_check_installed.stat.exists
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:
@@ -34,39 +34,30 @@
become: false
run_once: true
check_mode: false
ansible.builtin.command: |-
git rev-parse --show-toplevel
ansible.builtin.command: git rev-parse --show-toplevel
register: repository_path
- name: Copy kubeconfig project directory
run_once: true
- name: Copy kubeconfig to the project directory
when: k3s_primary_control_node
ansible.builtin.fetch:
src: "/etc/rancher/k3s/k3s.yaml"
src: /etc/rancher/k3s/k3s.yaml
dest: "{{ repository_path.stdout }}/kubeconfig"
flat: true
when:
- k3s_control_node is defined
- k3s_control_node
- name: Update kubeconfig with the correct IPv4 address
- name: Update kubeconfig with the correct load balancer address
delegate_to: localhost
become: false
run_once: true
ansible.builtin.replace:
path: "{{ repository_path.stdout }}/kubeconfig"
regexp: "https://127.0.0.1:6443"
regexp: https://127.0.0.1:6443
replace: "https://{{ k3s_registration_address }}:6443"
# Unmanaging and removing the Cilium HelmChart is required for
# flux to take over managing the lifecycle of Cilium
- name: Post installation of custom manifests tasks
run_once: true
- name: Post installation of custom manifests
when:
- k3s_server_manifests_templates | length > 0
or k3s_server_manifests_urls | length > 0
- k3s_control_node is defined
- k3s_control_node
- k3s_primary_control_node
- (k3s_server_manifests_templates | length > 0
or k3s_server_manifests_urls | length > 0)
block:
- name: Wait for custom manifests to rollout
kubernetes.core.k8s_info:
@@ -98,6 +89,8 @@
type: Complete
status: true
wait_timeout: 360
# Unmanage and remove the Cilium HelmChart in-order for
# flux to take over managing the lifecycle of Cilium
- name: Patch the Cilium HelmChart to unmanage it
kubernetes.core.k8s_json_patch:
kubeconfig: /etc/rancher/k3s/k3s.yaml
@@ -122,7 +115,7 @@
kind: HelmChart
namespace: kube-system
register: cilium_helmchart
- name: Remove finializers on the Cilium HelmChart
- name: Force delete the Cilium HelmChart
when: cilium_helmchart.resources | count > 0
kubernetes.core.k8s:
kubeconfig: /etc/rancher/k3s/k3s.yaml
@@ -137,17 +130,18 @@
# 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: 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: Delete all custom manifest files
ansible.builtin.file:
path: "{{ item.path }}"
state: absent
loop: "{{ custom_manifest.files }}"
- name: Delete custom manifests
when: k3s_primary_control_node
block:
- 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: Delete all custom manifest files
ansible.builtin.file:
path: "{{ item.path }}"
state: absent
loop: "{{ custom_manifest.files }}"