mirror of
https://github.com/PyratLabs/ansible-role-k3s
synced 2024-11-13 08:50:20 +01:00
c743df868b
This release also fixes: - #38 : removing the --disable-agent option. Please use node taints. - #39 : clarified where jmespath should be installed in README.md
76 lines
2.8 KiB
YAML
76 lines
2.8 KiB
YAML
---
|
|
|
|
- name: Ensure k3s control node fact is set
|
|
set_fact:
|
|
k3s_control_node: "{{ 'false' if k3s_build_cluster else 'true' }}"
|
|
when: k3s_control_node is not defined
|
|
|
|
- name: Ensure k3s master control node fact is set
|
|
set_fact:
|
|
k3s_primary_control_node: "{{ 'false' if k3s_build_cluster else 'true' }}"
|
|
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 the control host
|
|
set_fact:
|
|
k3s_control_node: true
|
|
when: inventory_hostname == play_hosts[0]
|
|
when: true not in (hostvars | json_query('*.k3s_control_node'))
|
|
and k3s_build_cluster is defined and k3s_build_cluster
|
|
|
|
- name: Ensure a count of control masters is generated
|
|
set_fact:
|
|
k3s_controller_count: "{{ k3s_controller_count + [ item ] }}"
|
|
when: hostvars[item].k3s_control_node is defined
|
|
and 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 is defined
|
|
and k3s_controller_count | length > 1
|
|
and inventory_hostname == k3s_controller_count[0]
|
|
and k3s_build_cluster is defined and k3s_build_cluster
|
|
|
|
- name: Ensure ansible_host is mapped to inventory_hostname
|
|
lineinfile:
|
|
path: /tmp/inventory.txt
|
|
line: >-
|
|
{{ item }}
|
|
@@@
|
|
{{ hostvars[item].ansible_host | default(hostvars[item].ansible_fqdn) }}
|
|
@@@
|
|
C_{{ hostvars[item].k3s_control_node }}
|
|
@@@
|
|
P_{{ hostvars[item].k3s_primary_control_node | default(False) }}
|
|
create: true
|
|
regexp: "^{{ item }} @@@ {{ hostvars[item].ansible_host | default(hostvars[item].ansible_fqdn) }}"
|
|
mode: 0600
|
|
loop: "{{ play_hosts }}"
|
|
check_mode: false
|
|
when: hostvars[item].k3s_control_node is defined
|
|
|
|
- name: Delegate a master control plane node
|
|
block:
|
|
- name: Lookup control node from file
|
|
command: "grep '{{ 'P_True' if (k3s_controller_count | length > 1) else 'C_True' }}' /tmp/inventory.txt"
|
|
changed_when: false
|
|
check_mode: false
|
|
register: k3s_control_delegate_raw
|
|
|
|
- name: Ensure control node is delegated to for obtaining a token
|
|
set_fact:
|
|
k3s_control_delegate: "{{ k3s_control_delegate_raw.stdout.split(' @@@ ')[0] }}"
|
|
check_mode: false
|
|
when: k3s_control_delegate is not defined
|
|
|
|
- name: Ensure the control node address is registered in Ansible
|
|
set_fact:
|
|
k3s_control_node_address: "{{ hostvars[k3s_control_delegate].ansible_host | default(hostvars[k3s_control_delegate].ansible_fqdn) }}"
|
|
check_mode: false
|
|
when: k3s_control_node_address is not defined
|
|
|
|
when: k3s_control_node_address is not defined
|
|
or k3s_control_delegate is not defined
|