Fixed provisioning of multi-master, need to test LB with k3s_control_node_address

This commit is contained in:
Xan Manning 2020-01-11 22:42:29 +00:00
parent c3ae2b79eb
commit 09fc37e6ec
3 changed files with 20 additions and 5 deletions

View file

@ -9,5 +9,6 @@
- name: Set each node to be a control node
set_fact:
k3s_control_node: true
when: inventory_hostname in ['node2', 'node3']
roles:
- role: xanmanning.k3s

View file

@ -5,13 +5,15 @@
path: "{{ k3s_systemd_unit_directory }}"
state: directory
recurse: true
when: k3s_control_node
when: (k3s_control_node and k3s_controller_count | length == 1)
or (k3s_primary_control_node and k3s_controller_count | length > 1)
- name: Ensure k3s service unit file is present on control plane
template:
src: k3s.service.j2
dest: "{{ k3s_systemd_unit_directory }}/k3s.service"
when: k3s_control_node
when: (k3s_control_node and k3s_controller_count | length == 1)
or (k3s_primary_control_node and k3s_controller_count | length > 1)
notify:
- reload systemd
@ -36,4 +38,5 @@
state: started
enabled: true
scope: "{{ k3s_systemd_context }}"
when: k3s_control_node
when: (k3s_control_node and k3s_controller_count | length == 1)
or (k3s_primary_control_node and k3s_controller_count | length > 1)

View file

@ -5,6 +5,11 @@
k3s_control_node: false
when: k3s_control_node is not defined
- name: Ensure k3s master control node fact is set
set_fact:
k3s_primary_control_node: false
when: k3s_primary_control_node is not defined
- name: Ensure a k3s control node is defined if none are found in play_hosts
block:
- name: Set control host
@ -16,5 +21,11 @@
- name: Ensure a count of control masters is generated
set_fact:
k3s_controller_count: "{{ k3s_controller_count + [ item ] }}"
when: item
loop: "{{ hostvars | json_query('*.k3s_control_node') }}"
when: hostvars[item].k3s_control_node
loop: "{{ play_hosts }}"
- name: Ensure a primary k3s control node is defined if multiple are found in play_hosts
set_fact:
k3s_primary_control_node: true
when: k3s_controller_count | length > 1
and inventory_hostname == k3s_controller_count[0]