refactor(k3s): centralize k3s primary server IP and integrate Netcup DNS
Signed-off-by: Tuan-Dat Tran <tuan-dat.tran@tudattr.dev>
This commit is contained in:
@@ -12,18 +12,19 @@
|
||||
mode: "0755"
|
||||
|
||||
- name: Install K3s server with node taint and TLS SAN
|
||||
when: (host.ip == k3s.server.ips[0] and (not k3s_status.stat.exists))
|
||||
when: (ansible_default_ipv4.address == k3s_primary_server_ip and (not k3s_status.stat.exists))
|
||||
ansible.builtin.command: |
|
||||
/tmp/k3s_install.sh server \
|
||||
--node-taint CriticalAddonsOnly=true:NoExecute \
|
||||
--tls-san {{ hostvars['k3s-loadbalancer'].ansible_default_ipv4.address }}
|
||||
--tls-san {{ k3s_server_name }}
|
||||
become: true
|
||||
async: 300
|
||||
poll: 0
|
||||
register: k3s_primary_install
|
||||
|
||||
- name: Wait for K3s to be installed
|
||||
when: (host.ip == k3s.server.ips[0] and (not k3s_status.stat.exists))
|
||||
when: (ansible_default_ipv4.address == k3s_primary_server_ip and (not k3s_status.stat.exists))
|
||||
ansible.builtin.async_status:
|
||||
jid: "{{ k3s_primary_install.ansible_job_id }}"
|
||||
register: k3s_primary_install_status
|
||||
@@ -33,23 +34,23 @@
|
||||
become: true
|
||||
|
||||
- name: Get K3s token from the first server
|
||||
when: host.ip == k3s.server.ips[0]
|
||||
when: ansible_default_ipv4.address == k3s_primary_server_ip
|
||||
ansible.builtin.slurp:
|
||||
src: /var/lib/rancher/k3s/server/node-token
|
||||
register: k3s_token
|
||||
become: true
|
||||
|
||||
- name: Set fact on k3s.server.ips[0]
|
||||
when: host.ip == k3s.server.ips[0]
|
||||
- name: Set fact on k3s_primary_server_ip
|
||||
when: ansible_default_ipv4.address == k3s_primary_server_ip
|
||||
ansible.builtin.set_fact:
|
||||
k3s_token: "{{ k3s_token['content'] | b64decode | trim }}"
|
||||
|
||||
- name: Install K3s on the secondary servers
|
||||
when: (host.ip != k3s.server.ips[0] and (not k3s_status.stat.exists))
|
||||
when: (ansible_default_ipv4.address != k3s_primary_server_ip and (not k3s_status.stat.exists))
|
||||
ansible.builtin.command: |
|
||||
/tmp/k3s_install.sh server \
|
||||
--node-taint CriticalAddonsOnly=true:NoExecute \
|
||||
--tls-san {{ k3s.loadbalancer.ip }}
|
||||
environment:
|
||||
K3S_TOKEN: "{{ hostvars[(hostvars | dict2items | map(attribute='value') | map('dict2items') | map('selectattr', 'key', 'match', 'host') | map('selectattr', 'value.ip', 'match', k3s.server.ips[0] ) | select() | first | items2dict).host.hostname].k3s_token }}"
|
||||
K3S_TOKEN: "{{ hostvars[(hostvars | dict2items | map(attribute='value') | map('dict2items') | map('selectattr', 'key', 'match', 'host') | map('selectattr', 'value.ip', 'match', k3s_primary_server_ip ) | select() | first | items2dict).host.hostname].k3s_token }}"
|
||||
become: true
|
||||
|
||||
Reference in New Issue
Block a user