2019-03-09 21:54:44 +01:00
|
|
|
---
|
|
|
|
|
2021-02-27 20:02:49 +01:00
|
|
|
- name: "Ensure cluster token is captured from {{ k3s_control_delegate }}"
|
2020-12-12 15:27:59 +01:00
|
|
|
ansible.builtin.slurp:
|
2020-12-21 20:14:52 +01:00
|
|
|
path: "{{ k3s_runtime_config['data-dir'] | default(k3s_data_dir) }}/server/token"
|
|
|
|
register: k3s_slurped_cluster_token
|
2019-03-09 21:54:44 +01:00
|
|
|
delegate_to: "{{ k3s_control_delegate }}"
|
2021-02-16 16:46:01 +01:00
|
|
|
when:
|
|
|
|
- k3s_control_token is not defined
|
|
|
|
- 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
|
|
|
|
2020-12-21 20:14:52 +01:00
|
|
|
- name: Ensure cluster token is formatted correctly for use in templates
|
|
|
|
ansible.builtin.set_fact:
|
|
|
|
k3s_control_token: "{{ k3s_slurped_cluster_token.content | b64decode }}"
|
2020-07-25 18:39:01 +02:00
|
|
|
when: k3s_control_token is not defined and not ansible_check_mode
|
|
|
|
|
2020-12-21 20:14:52 +01:00
|
|
|
- name: Ensure dummy cluster token is defined for ansible_check_mode
|
|
|
|
ansible.builtin.set_fact:
|
2020-07-25 18:39:01 +02:00
|
|
|
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-12-21 20:14:52 +01:00
|
|
|
- name: Ensure the cluster token file location exists
|
2020-12-12 15:27:59 +01:00
|
|
|
ansible.builtin.file:
|
2020-12-05 22:56:28 +01:00
|
|
|
path: "{{ k3s_token_location | dirname }}"
|
2020-09-21 20:38:51 +02:00
|
|
|
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
|
2020-12-12 15:27:59 +01:00
|
|
|
ansible.builtin.template:
|
2020-09-21 20:38:51 +02:00
|
|
|
src: cluster-token.j2
|
2020-12-05 22:56:28 +01:00
|
|
|
dest: "{{ k3s_token_location }}"
|
2020-09-21 20:38:51 +02:00
|
|
|
mode: 0600
|
2020-10-19 21:26:12 +02:00
|
|
|
become: "{{ k3s_become_for_install_dir | ternary(true, false, k3s_become_for_all) }}"
|
2020-09-21 20:38:51 +02:00
|
|
|
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
|
2020-12-12 15:27:59 +01:00
|
|
|
ansible.builtin.template:
|
2019-03-09 21:54:44 +01:00
|
|
|
src: k3s.service.j2
|
2020-12-05 22:56:28 +01:00
|
|
|
dest: "{{ k3s_systemd_unit_dir }}/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-10-22 20:26:15 +02:00
|
|
|
- name: Ensure k3s config file exists
|
2020-12-12 15:27:59 +01:00
|
|
|
ansible.builtin.template:
|
2020-10-19 21:26:12 +02:00
|
|
|
src: config.yaml.j2
|
|
|
|
dest: "{{ k3s_config_file }}"
|
|
|
|
mode: 0644
|
|
|
|
notify:
|
|
|
|
- reload systemd
|
|
|
|
- restart k3s
|
|
|
|
become: "{{ k3s_become_for_install_dir | ternary(true, false, k3s_become_for_all) }}"
|
|
|
|
|
2020-11-10 20:01:05 +01:00
|
|
|
- name: Ensure secondary controllers are started
|
2020-12-12 15:27:59 +01:00
|
|
|
ansible.builtin.systemd:
|
2020-01-13 22:32:31 +01:00
|
|
|
name: k3s
|
|
|
|
state: started
|
2021-01-30 18:57:50 +01:00
|
|
|
enabled: "{{ k3s_start_on_boot }}"
|
2020-11-10 20:01:05 +01:00
|
|
|
register: ensure_secondary_controllers_started
|
2021-02-28 17:45:38 +01:00
|
|
|
failed_when:
|
|
|
|
- ensure_secondary_controllers_started is not succeeded
|
|
|
|
- not ansible_check_mode
|
2020-11-10 20:01:05 +01:00
|
|
|
until: ensure_secondary_controllers_started is succeeded
|
2020-12-16 12:02:15 +01:00
|
|
|
retries: "{{ ansible_play_hosts_all | length }}"
|
2020-09-18 13:09:56 +02:00
|
|
|
delay: 5
|
2021-02-16 16:46:01 +01:00
|
|
|
when:
|
|
|
|
- k3s_control_node
|
|
|
|
- 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
|
|
|
|
2020-12-21 20:14:52 +01:00
|
|
|
- import_tasks: ../validate/state/control-plane.yml
|
2020-10-17 19:26:30 +02:00
|
|
|
when: not k3s_skip_validation
|
2019-10-01 22:31:35 +02:00
|
|
|
|
2021-03-14 17:29:14 +01:00
|
|
|
- name: Flush Handlers
|
|
|
|
meta: flush_handlers
|
2020-01-13 22:32:31 +01:00
|
|
|
|
2020-12-21 20:14:52 +01:00
|
|
|
- import_tasks: ../validate/state/nodes.yml
|
2020-10-17 19:26:30 +02:00
|
|
|
when: not k3s_skip_validation
|