ansible-role-k3s/tasks/ensure_cluster.yml

88 lines
2.4 KiB
YAML
Raw Normal View History

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 }}"
ansible.builtin.slurp:
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 }}"
when:
- k3s_control_token is not defined
- not ansible_check_mode
become: "{{ k3s_become }}"
- name: Ensure cluster token is formatted correctly for use in templates
ansible.builtin.set_fact:
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
- name: Ensure dummy cluster token is defined for ansible_check_mode
ansible.builtin.set_fact:
k3s_control_token_content: "{{ k3s_control_delegate | to_uuid }}"
2020-07-25 18:39:01 +02:00
check_mode: false
when:
- ansible_check_mode
2019-03-09 21:54:44 +01:00
- name: Ensure the cluster token file location exists
ansible.builtin.file:
path: "{{ k3s_token_location | dirname }}"
state: directory
mode: 0755
become: "{{ k3s_become }}"
- name: Ensure k3s cluster token file is present
ansible.builtin.template:
src: cluster-token.j2
dest: "{{ k3s_token_location }}"
mode: 0600
become: "{{ k3s_become }}"
notify:
- restart k3s
2019-03-09 21:54:44 +01:00
- name: Ensure k3s service unit file is present
ansible.builtin.template:
2019-03-09 21:54:44 +01:00
src: k3s.service.j2
dest: "{{ k3s_systemd_unit_dir }}/k3s.service"
mode: 0644
become: "{{ k3s_become }}"
2019-03-09 21:54:44 +01:00
notify:
- reload systemd
2019-03-09 21:54:44 +01:00
- restart k3s
- name: Ensure k3s config file exists
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 }}"
2020-10-19 21:26:12 +02:00
- name: Ensure secondary controllers are started
ansible.builtin.systemd:
2020-01-13 22:32:31 +01:00
name: k3s
state: started
enabled: "{{ k3s_start_on_boot }}"
register: ensure_secondary_controllers_started
failed_when:
- ensure_secondary_controllers_started is not succeeded
- not ansible_check_mode
until: ensure_secondary_controllers_started is succeeded
retries: "{{ ansible_play_hosts | length }}"
delay: 5
when:
- k3s_control_node
- not k3s_primary_control_node
become: "{{ k3s_become }}"
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
- name: Flush Handlers
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