Skip to content

Commit

Permalink
Selectively remove existing token from the environment file
Browse files Browse the repository at this point in the history
If the existing token in the environment file is the same as the token
used for the playbook run, leave it in the file to avoid false changed
status from the task.
  • Loading branch information
anon-software committed Sep 27, 2024
1 parent f624a42 commit 9af4f54
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions roles/k3s_agent/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@
INSTALL_K3S_EXEC: "agent"
changed_when: true

- name: Delete any existing token from the environment
- 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"
search_string: "K3S_TOKEN="
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
Expand Down
8 changes: 4 additions & 4 deletions roles/k3s_server/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@
line: "{{ item }}"
with_items: "{{ extra_service_envs }}"

- name: Delete any existing token from the environment
- 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"
search_string: "K3S_TOKEN="
regexp: "^K3S_TOKEN=\\s*(?!{{ token }}\\s*$)"

# Add the token to the environment.
- name: Add token as an environment variable
Expand Down Expand Up @@ -187,11 +187,11 @@
- (groups[server_group] | length) > 1
- inventory_hostname != groups[server_group][0]
block:
- name: Delete any existing token from the environment
- 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"
search_string: "K3S_TOKEN="
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
Expand Down

0 comments on commit 9af4f54

Please sign in to comment.