--- - name: Ensure NODE_TOKEN is captured from control node slurp: path: "{{ k3s_runtime_config['data-dir'] | default ('/var/lib/rancher/k3s') }}/server/node-token" register: k3s_slurped_control_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 NODE_TOKEN is formatted correctly for use in templates set_fact: k3s_control_token: "{{ k3s_slurped_control_token.content | b64decode }}" 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 - name: Ensure the cluster NODE_TOKEN file location exists 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 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 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 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 service: name: k3s state: started enabled: true register: ensure_secondary_controllers_started until: ensure_secondary_controllers_started is succeeded retries: "{{ play_hosts | 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/check-control-plane.yml when: not k3s_skip_validation - meta: flush_handlers - import_tasks: ../validate/check-cluster-nodes-ready.yml when: not k3s_skip_validation