xoxys.k3s/tasks/init.yml
Robert Kaussow 5cfc5bc86c
Some checks failed
ci/woodpecker/push/lint Pipeline was successful
ci/woodpecker/push/test Pipeline failed
ci/woodpecker/push/docs unknown status
ci/woodpecker/push/notify Pipeline was successful
ci: migrate to woodpecker
2024-02-18 21:09:43 +01:00

56 lines
1.6 KiB
YAML

---
- name: Ensure k3s-init service is stopped
ansible.builtin.service:
name: k3s-init
state: stopped
failed_when: False
- name: Clean previous runs of k3s-init
ansible.builtin.command: systemctl reset-failed k3s-init
failed_when: False
changed_when: False
tags:
- skip_ansible_later
- name: Init cluster inside the transient k3s-init service
ansible.builtin.command:
cmd: >-
systemd-run
-p RestartSec=2
-p Restart=on-failure
--unit=k3s-init
{{ __k3s_binary }} server {{ __k3s_server_init_args }}
creates: "{{ __k3s_service_file }}"
register: __k3s_init
- when: __k3s_init.changed | bool
block:
- name: Verify that all nodes actually joined
ansible.builtin.command: >-
{{ __k3s_binary }} kubectl get nodes
-l "node-role.kubernetes.io/control-plane=true"
-o=jsonpath="{.items[*].metadata.name}"
register: __k3s_init_nodes
until: __k3s_init_nodes.rc == 0 and (__k3s_init_nodes.stdout.split() | length) == (k3s_server_nodes | length)
retries: 30
delay: 10
changed_when: False
always:
- name: Fetch k3s-init logs
ansible.builtin.command: journalctl --all --unit=k3s-init.service
changed_when: False
register: __k3s_init_log
- name: Save k3s-init logs
ansible.builtin.copy:
content: "{{ __k3s_init_log.stdout }}"
dest: "{{ __k3s_log_dir }}/k3s-init.log"
mode: "0640"
when: k3s_init_log_enabled | bool
- name: Kill the temporary service used for initialization
ansible.builtin.service:
name: k3s-init
state: stopped
failed_when: False