2019-03-09 21:54:44 +01:00
|
|
|
---
|
|
|
|
|
|
|
|
- name: Ensure NODE_TOKEN is captured from control node
|
|
|
|
slurp:
|
|
|
|
path: "/var/lib/rancher/k3s/server/node-token"
|
2019-12-04 18:17:15 +01:00
|
|
|
register: k3s_slurped_control_token
|
2019-03-09 21:54:44 +01:00
|
|
|
delegate_to: "{{ k3s_control_delegate }}"
|
2020-07-25 18:39:01 +02:00
|
|
|
when: k3s_control_token is not defined and not ansible_check_mode
|
2020-05-20 19:50:58 +02:00
|
|
|
become: "{{ k3s_become_for_kubectl | ternary(true, false, k3s_become_for_all) }}"
|
2019-12-04 18:17:15 +01:00
|
|
|
|
|
|
|
- name: Ensure NODE_TOKEN is formatted correctly for use in templates
|
|
|
|
set_fact:
|
|
|
|
k3s_control_token: "{{ k3s_slurped_control_token.content | b64decode }}"
|
2020-07-25 18:39:01 +02:00
|
|
|
when: k3s_control_token is not defined and not ansible_check_mode
|
|
|
|
|
|
|
|
- name: Ensure dummy NODE_TOKEN is defined for ansible_check_mode
|
|
|
|
set_fact:
|
|
|
|
k3s_control_token: "{{ k3s_control_delegate | to_uuid }}"
|
|
|
|
check_mode: false
|
|
|
|
when: k3s_control_token is not defined and ansible_check_mode
|
2019-03-09 21:54:44 +01:00
|
|
|
|
2020-09-21 20:38:51 +02:00
|
|
|
- name: Ensure the cluster NODE_TOKEN file location exists
|
|
|
|
file:
|
|
|
|
path: "{{ k3s_token_location }}"
|
|
|
|
state: directory
|
|
|
|
mode: 0755
|
|
|
|
become: "{{ k3s_become_for_systemd | ternary(true, false, k3s_become_for_all) }}"
|
|
|
|
|
|
|
|
- name: Ensure k3s cluster token file is present on workers and secondary control nodes
|
|
|
|
template:
|
|
|
|
src: cluster-token.j2
|
|
|
|
dest: "{{ k3s_token_location }}/cluster-token"
|
|
|
|
mode: 0600
|
|
|
|
become: "{{ k3s_become_for_systemd | ternary(true, false, k3s_become_for_all) }}"
|
|
|
|
when: (k3s_control_node and not k3s_primary_control_node)
|
|
|
|
or not k3s_control_node
|
|
|
|
notify:
|
|
|
|
- restart k3s
|
|
|
|
|
2019-03-09 21:54:44 +01:00
|
|
|
- name: Ensure k3s service unit file is present
|
|
|
|
template:
|
|
|
|
src: k3s.service.j2
|
2020-05-31 12:42:02 +02:00
|
|
|
dest: "{{ k3s_systemd_unit_directory }}/k3s.service"
|
2020-09-15 19:10:25 +02:00
|
|
|
mode: 0644
|
2020-05-09 20:53:25 +02:00
|
|
|
become: "{{ k3s_become_for_systemd | ternary(true, false, k3s_become_for_all) }}"
|
2019-03-09 21:54:44 +01:00
|
|
|
notify:
|
2019-10-01 22:31:35 +02:00
|
|
|
- reload systemd
|
2019-03-09 21:54:44 +01:00
|
|
|
- restart k3s
|
|
|
|
|
2020-01-13 22:32:31 +01:00
|
|
|
- name: Ensure secondary masters are started
|
|
|
|
service:
|
|
|
|
name: k3s
|
|
|
|
state: started
|
|
|
|
enabled: true
|
2020-03-07 17:15:41 +01:00
|
|
|
register: ensure_secondary_masters_started
|
|
|
|
until: ensure_secondary_masters_started is succeeded
|
|
|
|
retries: "{{ play_hosts | length }}"
|
2020-09-18 13:09:56 +02:00
|
|
|
delay: 5
|
2020-01-13 22:32:31 +01:00
|
|
|
when: k3s_control_node and not k3s_primary_control_node
|
2020-05-30 23:40:05 +02:00
|
|
|
become: "{{ k3s_become_for_systemd | ternary(true, false, k3s_become_for_all) }}"
|
2019-03-09 21:54:44 +01:00
|
|
|
|
2019-10-01 22:31:35 +02:00
|
|
|
- name: Wait for control plane to be ready to accept connections
|
|
|
|
wait_for:
|
2019-10-26 23:49:48 +02:00
|
|
|
port: "{{ k3s_https_port }}"
|
2020-05-20 19:50:58 +02:00
|
|
|
host: "{{ k3s_bind_address | default('127.0.0.1') }}"
|
2019-10-01 22:31:35 +02:00
|
|
|
delay: 5
|
|
|
|
sleep: 5
|
|
|
|
timeout: 300
|
|
|
|
when: k3s_control_node
|
|
|
|
|
2020-01-13 22:32:31 +01:00
|
|
|
- meta: flush_handlers
|
|
|
|
|
2019-03-09 21:54:44 +01:00
|
|
|
- name: Wait for all nodes to be ready
|
|
|
|
command: "{{ k3s_install_dir }}/kubectl get nodes"
|
|
|
|
changed_when: false
|
2019-10-01 22:31:35 +02:00
|
|
|
failed_when: false
|
2019-03-09 21:54:44 +01:00
|
|
|
register: kubectl_get_nodes_result
|
2019-10-01 22:31:35 +02:00
|
|
|
until: kubectl_get_nodes_result.rc == 0
|
|
|
|
and kubectl_get_nodes_result.stdout.find("NotReady") == -1
|
2019-03-09 21:54:44 +01:00
|
|
|
retries: 30
|
|
|
|
delay: 20
|
2020-07-25 18:39:01 +02:00
|
|
|
when: k3s_control_node and not k3s_no_flannel and not ansible_check_mode
|
2020-05-20 19:50:58 +02:00
|
|
|
become: "{{ k3s_become_for_kubectl | ternary(true, false, k3s_become_for_all) }}"
|