Skip to content

Commit

Permalink
k3s no longer runs if token isn't provided
Browse files Browse the repository at this point in the history
  • Loading branch information
wtripp180901 committed Jan 15, 2025
1 parent 5f7e48f commit ddca636
Showing 1 changed file with 33 additions and 25 deletions.
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.

0 comments on commit ddca636

Please sign in to comment.