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
|
2022-01-02 22:52:09 +01:00
|
|
|
become: "{{ k3s_become }}"
|
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:
|
2022-05-29 19:55:01 +02:00
|
|
|
k3s_control_token_content: "{{ k3s_control_token | default(k3s_slurped_cluster_token.content | b64decode) }}"
|
|
|
|
when:
|
|
|
|
- k3s_control_token is not defined
|
|
|
|
- not ansible_check_mode
|
2020-07-25 18:39:01 +02:00
|
|
|
|
2020-12-21 20:14:52 +01:00
|
|
|
- name: Ensure dummy cluster token is defined for ansible_check_mode
|
|
|
|
ansible.builtin.set_fact:
|
2022-05-29 19:55:01 +02:00
|
|
|
k3s_control_token_content: "{{ k3s_control_delegate | to_uuid }}"
|
2020-07-25 18:39:01 +02:00
|
|
|
check_mode: false
|
2022-05-29 19:55:01 +02:00
|
|
|
when:
|
|
|
|
- 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
|
2022-01-02 22:52:09 +01:00
|
|
|
become: "{{ k3s_become }}"
|
2020-09-21 20:38:51 +02:00
|
|
|
|
2021-07-24 18:21:31 +02:00
|
|
|
- name: Ensure k3s cluster token file is present
|
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
|
2022-01-02 22:52:09 +01:00
|
|
|
become: "{{ k3s_become }}"
|
2020-09-21 20:38:51 +02:00
|
|
|
notify:
|
2022-05-03 20:02:02 +02:00
|
|
|
- "restart k3s {{ k3s_service_handler[ansible_service_mgr] }}"
|
2020-09-21 20:38:51 +02:00
|
|
|
|
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
|
2022-01-02 22:52:09 +01:00
|
|
|
become: "{{ k3s_become }}"
|
2022-06-15 23:03:39 +02:00
|
|
|
when:
|
|
|
|
- k3s_service_handler[ansible_service_mgr] == 'systemd'
|
|
|
|
notify:
|
|
|
|
- "reload {{ k3s_service_handler[ansible_service_mgr] }}"
|
|
|
|
- "restart k3s {{ k3s_service_handler[ansible_service_mgr] }}"
|
|
|
|
|
|
|
|
- name: Ensure k3s service file is present
|
|
|
|
ansible.builtin.template:
|
|
|
|
src: k3s.openrc.j2
|
|
|
|
dest: "{{ k3s_openrc_service_dir }}/k3s"
|
|
|
|
mode: 0744
|
|
|
|
when:
|
|
|
|
- k3s_service_handler[ansible_service_mgr] == 'service'
|
2019-03-09 21:54:44 +01:00
|
|
|
notify:
|
2022-05-03 20:02:02 +02:00
|
|
|
- "reload {{ k3s_service_handler[ansible_service_mgr] }}"
|
|
|
|
- "restart k3s {{ k3s_service_handler[ansible_service_mgr] }}"
|
2022-06-15 23:03:39 +02:00
|
|
|
become: "{{ k3s_become }}"
|
|
|
|
|
|
|
|
- name: Ensure k3s logrotate file is present
|
|
|
|
ansible.builtin.template:
|
|
|
|
src: k3s.logrotate.j2
|
|
|
|
dest: "{{ k3s_logrotate_dir }}/k3s"
|
|
|
|
mode: 0640
|
|
|
|
when:
|
|
|
|
- k3s_service_handler[ansible_service_mgr] == 'service'
|
|
|
|
notify:
|
|
|
|
- "reload {{ k3s_service_handler[ansible_service_mgr] }}"
|
|
|
|
- "restart k3s {{ k3s_service_handler[ansible_service_mgr] }}"
|
|
|
|
become: "{{ k3s_become }}"
|
2019-03-09 21:54:44 +01:00
|
|
|
|
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:
|
2022-05-03 20:02:02 +02:00
|
|
|
- "reload {{ k3s_service_handler[ansible_service_mgr] }}"
|
|
|
|
- "restart k3s {{ k3s_service_handler[ansible_service_mgr] }}"
|
2022-01-02 22:52:09 +01:00
|
|
|
become: "{{ k3s_become }}"
|
2020-10-19 21:26:12 +02:00
|
|
|
|
2020-11-10 20:01:05 +01:00
|
|
|
- name: Ensure secondary controllers are started
|
2022-06-15 19:45:54 +02:00
|
|
|
include_tasks: ensure_control_plane_started_{{ ansible_service_mgr }}.yml
|
2021-02-16 16:46:01 +01:00
|
|
|
when:
|
|
|
|
- k3s_control_node
|
|
|
|
- not k3s_primary_control_node
|
2019-03-09 21:54:44 +01:00
|
|
|
|
2021-06-22 21:47:58 +02:00
|
|
|
- import_tasks: post_checks_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
|
2022-05-02 18:13:12 +02:00
|
|
|
ansible.builtin.meta: flush_handlers
|
2020-01-13 22:32:31 +01:00
|
|
|
|
2021-06-22 21:47:58 +02:00
|
|
|
- import_tasks: post_checks_nodes.yml
|
2020-10-17 19:26:30 +02:00
|
|
|
when: not k3s_skip_validation
|