mirror of
https://github.com/PyratLabs/ansible-role-k3s.git
synced 2024-11-30 13:04:19 +01:00
69 lines
2.0 KiB
YAML
69 lines
2.0 KiB
YAML
---
|
|
|
|
- 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) }}
|
|
@@@
|
|
{{ hostvars[item].k3s_control_node }}
|
|
create: true
|
|
loop: "{{ play_hosts }}"
|
|
|
|
- name: Lookup control node from file
|
|
command: "grep 'True' /tmp/inventory.txt"
|
|
changed_when: 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] }}"
|
|
|
|
- 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) }}"
|
|
when: k3s_control_node_address is not defined
|
|
|
|
- name: Ensure NODE_TOKEN is captured from control node
|
|
slurp:
|
|
path: "/var/lib/rancher/k3s/server/node-token"
|
|
register: k3s_slurped_control_token
|
|
delegate_to: "{{ k3s_control_delegate }}"
|
|
when: k3s_control_token is not defined
|
|
|
|
- name: Ensure NODE_TOKEN is formatted correctly for use in templates
|
|
set_fact:
|
|
k3s_control_token: "{{ k3s_slurped_control_token.content | b64decode }}"
|
|
when: k3s_control_token is not defined
|
|
|
|
- name: Ensure k3s service unit file is present
|
|
template:
|
|
src: k3s.service.j2
|
|
dest: /etc/systemd/system/k3s.service
|
|
notify:
|
|
- reload systemd
|
|
- restart k3s
|
|
|
|
- meta: flush_handlers
|
|
|
|
- name: Wait for control plane to be ready to accept connections
|
|
wait_for:
|
|
port: "{{ k3s_https_port }}"
|
|
delay: 5
|
|
sleep: 5
|
|
timeout: 300
|
|
when: k3s_control_node
|
|
|
|
- name: Wait for all nodes to be ready
|
|
command: "{{ k3s_install_dir }}/kubectl get nodes"
|
|
changed_when: false
|
|
failed_when: false
|
|
register: kubectl_get_nodes_result
|
|
until: kubectl_get_nodes_result.rc == 0
|
|
and kubectl_get_nodes_result.stdout.find("NotReady") == -1
|
|
retries: 30
|
|
delay: 20
|
|
when: k3s_control_node
|