Compare commits
3 Commits
6b258763be
...
19c24bd503
Author | SHA1 | Date |
---|---|---|
paradon | 19c24bd503 | |
fragpit | 0c0d3bb38d | |
davidg | cfd9400edf |
|
@ -26,7 +26,7 @@
|
|||
- name: Ensure uninstalled nodes are drained # noqa no-changed-when
|
||||
ansible.builtin.command:
|
||||
cmd: >-
|
||||
{{ k3s_install_dir }}/kubectl drain {{ item }}
|
||||
{{ k3s_install_dir }}/kubectl drain {{ hostvars[item].ansible_hostname }}
|
||||
--ignore-daemonsets
|
||||
--{{ k3s_drain_command[ansible_version.string is version_compare('1.22', '>=')] }}
|
||||
--force
|
||||
|
@ -42,7 +42,7 @@
|
|||
|
||||
- name: Ensure uninstalled nodes are removed # noqa no-changed-when
|
||||
ansible.builtin.command:
|
||||
cmd: "{{ k3s_install_dir }}/kubectl delete node {{ item }}"
|
||||
cmd: "{{ k3s_install_dir }}/kubectl delete node {{ hostvars[item].ansible_hostname }}"
|
||||
delegate_to: "{{ k3s_control_delegate }}"
|
||||
run_once: true
|
||||
when:
|
||||
|
|
|
@ -55,6 +55,42 @@
|
|||
- hostvars[item].k3s_control_node
|
||||
loop: "{{ ansible_play_hosts }}"
|
||||
|
||||
- name: Ensure an existing primary k3s control node is defined if multiple are found and at least one is running
|
||||
when:
|
||||
- k3s_controller_list | length >= 1
|
||||
- k3s_build_cluster is defined
|
||||
- k3s_build_cluster
|
||||
- k3s_control_delegate is not defined
|
||||
block:
|
||||
- name: Test if control plane is running
|
||||
ansible.builtin.wait_for:
|
||||
port: "{{ k3s_runtime_config['https-listen-port'] | default('6443') }}"
|
||||
host: "{{ k3s_runtime_config['bind-address'] | default('127.0.0.1') }}"
|
||||
timeout: 5
|
||||
register: k3s_control_node_running
|
||||
ignore_errors: true
|
||||
when: k3s_control_node
|
||||
|
||||
- name: List running control planes
|
||||
ansible.builtin.set_fact:
|
||||
k3s_running_controller_list: "{{ k3s_running_controller_list + [item] }}"
|
||||
when:
|
||||
- hostvars[item].k3s_control_node_running is not skipped
|
||||
- hostvars[item].k3s_control_node_running is succeeded
|
||||
loop: "{{ ansible_play_hosts }}"
|
||||
|
||||
- name: Choose first running node as delegate
|
||||
ansible.builtin.set_fact:
|
||||
k3s_control_delegate: "{{ k3s_running_controller_list[0] }}"
|
||||
when: k3s_running_controller_list | length >= 1
|
||||
|
||||
- name: Ensure k3s_primary_control_node is set on the delegate
|
||||
ansible.builtin.set_fact:
|
||||
k3s_primary_control_node: true
|
||||
when:
|
||||
- k3s_control_delegate is defined
|
||||
- inventory_hostname == k3s_control_delegate
|
||||
|
||||
- name: Ensure a primary k3s control node is defined if multiple are found in ansible_play_hosts
|
||||
ansible.builtin.set_fact:
|
||||
k3s_primary_control_node: true
|
||||
|
@ -63,6 +99,7 @@
|
|||
- inventory_hostname == k3s_controller_list[0]
|
||||
- k3s_build_cluster is defined
|
||||
- k3s_build_cluster
|
||||
- k3s_control_delegate is not defined
|
||||
|
||||
- name: Ensure ansible_host is mapped to inventory_hostname
|
||||
ansible.builtin.blockinfile:
|
||||
|
|
|
@ -44,3 +44,6 @@
|
|||
- k3s_build_cluster is defined
|
||||
- k3s_build_cluster
|
||||
- k3s_registration_address is defined
|
||||
|
||||
- name: Flush Handlers
|
||||
ansible.builtin.meta: flush_handlers
|
||||
|
|
|
@ -77,6 +77,7 @@ k3s_conf_build_cluster: "{{
|
|||
|
||||
# Empty array for counting the number of control plane nodes
|
||||
k3s_controller_list: []
|
||||
k3s_running_controller_list: []
|
||||
|
||||
# Control plane port default
|
||||
k3s_control_plane_port: "{{ k3s_runtime_config['https-listen-port'] | default(6443) }}"
|
||||
|
|
Loading…
Reference in New Issue