Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent multiple tokens in k3s.service.env #364

Merged
merged 2 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions roles/k3s_agent/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
12 changes: 12 additions & 0 deletions roles/k3s_server/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
Loading