--- # tasks file for ansible-k3s - name: K3s aur instalation (Archlinux) aur: name: k3s-bin state: present become: true become_user: aur_builder - name: create config directory ansible.builtin.file: state: directory path: "{{ item }}" owner: root mode: 733 become: true loop: - "/etc/rancher/node/" - "/etc/rancher/k3s/" - name: Check if k3s token file exists on the first node run_once: true ansible.builtin.stat: path: "{{ k3s_token_file }}" register: k3s_token_file_stat become: true - name: Generate k3s token file on the first node if not exist yet run_once: true when: not k3s_token_file_stat.stat.exists ansible.builtin.copy: content: "{{ lookup('community.general.random_string', length=32) }}" dest: "{{ k3s_token_file }}" mode: 0600 become: true - name: Get k3s token from the first node run_once: true ansible.builtin.slurp: src: "{{ k3s_token_file }}" register: k3s_token_base64 become: true - name: Ensure all nodes has the same token ansible.builtin.copy: content: "{{ k3s_token_base64.content | b64decode }}" dest: "{{ k3s_token_file }}" mode: 0600 become: true - name: Copy k3s config files ansible.builtin.template: src: "{{ item.src }}" dest: "{{ item.dest }}" mode: 0644 loop: - src: config.yaml.j2 dest: "/etc/rancher/k3s/config.yaml" - src: k3s.service.j2 dest: "/etc/systemd/system/k3s.service" become: true - name: Template consul service ansible.builtin.template: src: consul.d/k3s.hcl.j2 dest: /etc/consul.d/k3s.hcl owner: consul mode: "0644" notify: Reload consul configuration on Linux when: k3s_consul_service become: true - name: Enable k3s service ansible.builtin.systemd: name: k3s enabled: true state: started register: k3s_service until: k3s_service is succeeded retries: 5 become: true