fix: add k3s reset logic for primary control plane
Some checks failed
Deploy Cluster / Terraform (push) Successful in 39s
Deploy Cluster / Ansible (push) Failing after 4m19s

This commit is contained in:
2026-03-21 16:10:17 +00:00
parent d4fd43e2f5
commit 8d1f9f4944

View File

@@ -28,27 +28,22 @@
stat: stat:
path: /usr/local/bin/k3s-uninstall.sh path: /usr/local/bin/k3s-uninstall.sh
register: k3s_uninstall_script register: k3s_uninstall_script
when: when: k3s_install_needed
- not (k3s_primary | default(false))
- k3s_install_needed
- name: Reset broken secondary k3s install before rejoin - name: Reset broken k3s install before reinstall
command: /usr/local/bin/k3s-uninstall.sh command: /usr/local/bin/k3s-uninstall.sh
when: when:
- not (k3s_primary | default(false))
- k3s_install_needed - k3s_install_needed
- k3s_uninstall_script.stat.exists - k3s_uninstall_script.stat.exists
- name: Remove stale k3s data on secondary - name: Remove stale k3s data
file: file:
path: "{{ item }}" path: "{{ item }}"
state: absent state: absent
loop: loop:
- /etc/rancher/k3s - /etc/rancher/k3s
- /var/lib/rancher/k3s - /var/lib/rancher/k3s
when: when: k3s_install_needed
- not (k3s_primary | default(false))
- k3s_install_needed
- name: Download k3s install script - name: Download k3s install script
get_url: get_url:
@@ -58,19 +53,22 @@
when: k3s_install_needed when: k3s_install_needed
- name: Install k3s server (primary) - name: Install k3s server (primary)
environment: environment:
INSTALL_K3S_VERSION: "{{ k3s_version if k3s_version != 'latest' else '' }}" INSTALL_K3S_VERSION: "{{ k3s_version if k3s_version != 'latest' else '' }}"
K3S_TOKEN: "{{ k3s_token }}" K3S_TOKEN: "{{ k3s_token }}"
command: >- command: >-
/tmp/install-k3s.sh server /tmp/install-k3s.sh server
--cluster-init --cluster-init
--advertise-address={{ k3s_primary_ip }} --advertise-address={{ k3s_primary_ip }}
--node-ip={{ k3s_node_ip }} --node-ip={{ k3s_node_ip }}
--tls-san={{ k3s_primary_ip }} --tls-san={{ k3s_primary_ip }}
--tls-san={{ k3s_primary_public_ip }} --tls-san={{ k3s_primary_public_ip }}
when: {% if k3s_disable_embedded_ccm | bool %}--disable-cloud-controller{% endif %}
- k3s_install_needed {% if k3s_disable_servicelb | bool %}--disable=servicelb{% endif %}
- k3s_primary | default(false) {% if k3s_kubelet_cloud_provider_external | bool %}--kubelet-arg=cloud-provider=external{% endif %}
when:
- k3s_install_needed
- k3s_primary | default(false)
- name: Install k3s server (secondary) - name: Install k3s server (secondary)
when: when:
@@ -86,6 +84,9 @@
--server https://{{ k3s_primary_ip }}:6443 --server https://{{ k3s_primary_ip }}:6443
--advertise-address={{ k3s_node_ip }} --advertise-address={{ k3s_node_ip }}
--node-ip={{ k3s_node_ip }} --node-ip={{ k3s_node_ip }}
{% if k3s_disable_embedded_ccm | bool %}--disable-cloud-controller{% endif %}
{% if k3s_disable_servicelb | bool %}--disable=servicelb{% endif %}
{% if k3s_kubelet_cloud_provider_external | bool %}--kubelet-arg=cloud-provider=external{% endif %}
register: secondary_install register: secondary_install
rescue: rescue: