diff --git a/roles/k3s_agent/tasks/main.yml b/roles/k3s_agent/tasks/main.yml index 2dafa3ce..565ef258 100644 --- a/roles/k3s_agent/tasks/main.yml +++ b/roles/k3s_agent/tasks/main.yml @@ -35,6 +35,12 @@ INSTALL_K3S_EXEC: "agent" changed_when: true +- name: Delete any existing token from the environment if different from the new one + ansible.builtin.lineinfile: + state: absent + path: "{{ systemd_dir }}/k3s-agent.service.env" + regexp: "^K3S_TOKEN=\\s*(?!{{ token }}\\s*$)" + - name: Add the token for joining the cluster to the environment no_log: true # avoid logging the server token ansible.builtin.lineinfile: diff --git a/roles/k3s_server/tasks/main.yml b/roles/k3s_server/tasks/main.yml index a61eb0b6..12131f2a 100644 --- a/roles/k3s_server/tasks/main.yml +++ b/roles/k3s_server/tasks/main.yml @@ -86,6 +86,12 @@ line: "{{ item }}" with_items: "{{ extra_service_envs }}" + - name: Delete any existing token from the environment if different from the new one + ansible.builtin.lineinfile: + state: absent + path: "{{ systemd_dir }}/k3s.service.env" + regexp: "^K3S_TOKEN=\\s*(?!{{ token }}\\s*$)" + # Add the token to the environment. - name: Add token as an environment variable no_log: true # avoid logging the server token @@ -181,6 +187,12 @@ - (groups[server_group] | length) > 1 - inventory_hostname != groups[server_group][0] block: + - name: Delete any existing token from the environment if different from the new one + ansible.builtin.lineinfile: + state: absent + path: "{{ systemd_dir }}/k3s.service.env" + regexp: "^K3S_TOKEN=\\s*(?!{{ token }}\\s*$)" + - name: Add the token for joining the cluster to the environment no_log: true # avoid logging the server token ansible.builtin.lineinfile: