mirror of
https://github.com/PyratLabs/ansible-role-k3s
synced 2024-11-05 13:23:30 +01:00
e7c714424c
* Tidy up and refactoring of tasks - `k3s_config_dir` derived from `k3s_config_file`, reused throughout the role to allow for easy removal of "Rancher" references #73. - `k3s_token_location` has moved to be in `k3s_config_dir`. - Tasks for creating directories now looped to caputure configuration from `k3s_server` and `k3s_agent` and ensure directories exist before k3s starts, see #75. - Server token collected directly from token file, not symlinked file (node-token). - `k3s_runtime_config` defined in `vars/` for validation and overwritten in tasks for control plane and workers. - Removed unused references to GitHub API. * set_fact now uses FQCN * re-pin molecule<3.2 * Command module now uses FQCN * Added package checks for #72 * Reorder task files - Docker tasks moved into a separate directory for ease of removal #67 - Bugfix: Control plane on alternate port didn't work. - Validation tasks grouped * Fix Fedora tests * Add optional documentation links to validations steps #76 * Removed jmespath requirement * Fix issue with data collection * Release candidate
78 lines
2.7 KiB
YAML
78 lines
2.7 KiB
YAML
---
|
|
|
|
- name: Ensure cluster token is captured from control node
|
|
ansible.builtin.slurp:
|
|
path: "{{ k3s_runtime_config['data-dir'] | default(k3s_data_dir) }}/server/token"
|
|
register: k3s_slurped_cluster_token
|
|
delegate_to: "{{ k3s_control_delegate }}"
|
|
when: k3s_control_token is not defined and not ansible_check_mode
|
|
become: "{{ k3s_become_for_kubectl | ternary(true, false, k3s_become_for_all) }}"
|
|
|
|
- name: Ensure cluster token is formatted correctly for use in templates
|
|
ansible.builtin.set_fact:
|
|
k3s_control_token: "{{ k3s_slurped_cluster_token.content | b64decode }}"
|
|
when: k3s_control_token is not defined and not ansible_check_mode
|
|
|
|
- name: Ensure dummy cluster token is defined for ansible_check_mode
|
|
ansible.builtin.set_fact:
|
|
k3s_control_token: "{{ k3s_control_delegate | to_uuid }}"
|
|
check_mode: false
|
|
when: k3s_control_token is not defined and ansible_check_mode
|
|
|
|
- name: Ensure the cluster token file location exists
|
|
ansible.builtin.file:
|
|
path: "{{ k3s_token_location | dirname }}"
|
|
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
|
|
ansible.builtin.template:
|
|
src: cluster-token.j2
|
|
dest: "{{ k3s_token_location }}"
|
|
mode: 0600
|
|
become: "{{ k3s_become_for_install_dir | 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
|
|
|
|
- name: Ensure k3s service unit file is present
|
|
ansible.builtin.template:
|
|
src: k3s.service.j2
|
|
dest: "{{ k3s_systemd_unit_dir }}/k3s.service"
|
|
mode: 0644
|
|
become: "{{ k3s_become_for_systemd | ternary(true, false, k3s_become_for_all) }}"
|
|
notify:
|
|
- reload systemd
|
|
- restart k3s
|
|
|
|
- name: Ensure k3s config file exists
|
|
ansible.builtin.template:
|
|
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) }}"
|
|
|
|
- name: Ensure secondary controllers are started
|
|
ansible.builtin.systemd:
|
|
name: k3s
|
|
state: started
|
|
enabled: true
|
|
register: ensure_secondary_controllers_started
|
|
until: ensure_secondary_controllers_started is succeeded
|
|
retries: "{{ ansible_play_hosts_all | length }}"
|
|
delay: 5
|
|
when: k3s_control_node and not k3s_primary_control_node
|
|
become: "{{ k3s_become_for_systemd | ternary(true, false, k3s_become_for_all) }}"
|
|
|
|
- import_tasks: ../validate/state/control-plane.yml
|
|
when: not k3s_skip_validation
|
|
|
|
- meta: flush_handlers
|
|
|
|
- import_tasks: ../validate/state/nodes.yml
|
|
when: not k3s_skip_validation
|