2024-09-19 23:10:00 +02:00
|
|
|
---
|
2024-09-20 16:57:59 +02:00
|
|
|
- name: See if k3s file exists
|
2024-10-08 04:13:38 +02:00
|
|
|
ansible.builtin.stat:
|
2024-09-20 16:57:59 +02:00
|
|
|
path: /usr/local/bin/k3s
|
|
|
|
register: k3s_status
|
|
|
|
|
|
|
|
- name: Download K3s install script to /tmp/
|
|
|
|
when: not k3s_status.stat.exists
|
|
|
|
ansible.builtin.get_url:
|
|
|
|
url: https://get.k3s.io
|
|
|
|
dest: /tmp/k3s_install.sh
|
|
|
|
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))
|
2024-10-08 04:13:38 +02:00
|
|
|
ansible.builtin.command: |
|
2024-09-20 16:57:59 +02:00
|
|
|
/tmp/k3s_install.sh server \
|
|
|
|
--node-taint CriticalAddonsOnly=true:NoExecute \
|
|
|
|
--tls-san {{ k3s.loadbalancer.ip }}
|
|
|
|
environment:
|
|
|
|
K3S_DATASTORE_ENDPOINT: "{{ k3s_db_connection_string }}"
|
|
|
|
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))
|
|
|
|
async_status:
|
|
|
|
jid: "{{ k3s_primary_install.ansible_job_id }}"
|
|
|
|
register: k3s_primary_install_status
|
|
|
|
until: k3s_primary_install_status.finished
|
|
|
|
retries: 60
|
|
|
|
delay: 5
|
|
|
|
become: true
|
2024-09-20 15:01:33 +02:00
|
|
|
|
|
|
|
- name: Get K3s token from the first server
|
|
|
|
when: host.ip == k3s.server.ips[0]
|
|
|
|
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]
|
2024-10-08 04:13:38 +02:00
|
|
|
ansible.builtin.set_fact: k3s_token="{{ k3s_token['content'] | b64decode | trim }}"
|
2024-09-20 15:01:33 +02:00
|
|
|
|
|
|
|
- name: Install K3s on the secondary servers
|
2024-09-20 16:57:59 +02:00
|
|
|
when: (host.ip != k3s.server.ips[0] and (not k3s_status.stat.exists))
|
2024-10-08 04:13:38 +02:00
|
|
|
ansible.builtin.command: |
|
2024-09-20 15:01:33 +02:00
|
|
|
/tmp/k3s_install.sh server \
|
|
|
|
--node-taint CriticalAddonsOnly=true:NoExecute \
|
|
|
|
--tls-san {{ k3s.loadbalancer.ip }}
|
2024-09-19 23:10:00 +02:00
|
|
|
environment:
|
|
|
|
K3S_DATASTORE_ENDPOINT: "{{ k3s_db_connection_string }}"
|
2024-09-20 15:01:33 +02:00
|
|
|
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 }}"
|
2024-09-19 23:10:00 +02:00
|
|
|
become: true
|