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

K3s no longer runs if token isn't provided #538

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
58 changes: 33 additions & 25 deletions ansible/roles/k3s/files/start_k3s.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,39 @@
k3s_server_name: "{{ os_metadata.meta.control_address }}"
service_name: "{{ 'k3s-agent' if k3s_server_name is defined else 'k3s' }}"
tasks:
- name: Ensure password directory exists
ansible.builtin.file:
path: "/etc/rancher/node"
state: directory
- name: "Start {{ service_name }}"
when: k3s_token is defined
block:
- name: Ensure password directory exists
ansible.builtin.file:
path: "/etc/rancher/node"
state: directory

- name: Set agent node password as token # uses token to keep password consistent between reimages
ansible.builtin.copy:
dest: /etc/rancher/node/password
content: "{{ k3s_token }}"

- name: Set agent node password as token # uses token to keep password consistent between reimages
ansible.builtin.copy:
dest: /etc/rancher/node/password
content: "{{ k3s_token }}"

- name: Add the token for joining the cluster to the environment
no_log: true # avoid logging the server token
ansible.builtin.lineinfile:
path: "/etc/systemd/system/{{ service_name }}.service.env"
line: "K3S_TOKEN={{ k3s_token }}"
- name: Add the token for joining the cluster to the environment
no_log: true # avoid logging the server token
ansible.builtin.lineinfile:
path: "/etc/systemd/system/{{ service_name }}.service.env"
line: "K3S_TOKEN={{ k3s_token }}"

- name: Add server url to agents
ansible.builtin.lineinfile:
path: "/etc/systemd/system/{{ service_name }}.service.env"
line: "K3S_URL=https://{{ k3s_server_name }}:6443"
when: k3s_server_name is defined
- name: Add server url to agents
ansible.builtin.lineinfile:
path: "/etc/systemd/system/{{ service_name }}.service.env"
line: "K3S_URL=https://{{ k3s_server_name }}:6443"
when: k3s_server_name is defined

- name: Start k3s service
ansible.builtin.systemd:
name: "{{ service_name }}"
daemon_reload: true
state: started
enabled: true
- name: Start k3s service
ansible.builtin.systemd:
name: "{{ service_name }}"
daemon_reload: true
state: started
enabled: true

- name: Output
when: k3s_token is undefined
ansible.builtin.debug:
msg: K3s token not defined in Openstack metadata, skipping.
Loading