Skip to content

Commit

Permalink
Add a handler to restart the K3s Server when the service file changes (
Browse files Browse the repository at this point in the history
…#344)

* Add a handler to restart the K3s Server when the service file changes

Signed-off-by: Peter Klijn <[email protected]>
  • Loading branch information
peterklijn authored Jul 15, 2024
1 parent 71d6ba0 commit 4f76954
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions roles/k3s_server/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
owner: root
group: root
mode: "0644"
register: service_file_single

- name: Copy K3s service file [HA]
when:
Expand All @@ -76,6 +77,7 @@
owner: root
group: root
mode: "0644"
register: service_file_ha

- name: Add service environment variables
when: extra_service_envs is defined
Expand All @@ -84,7 +86,18 @@
line: "{{ item }}"
with_items: "{{ extra_service_envs }}"

- name: Restart K3s service
when:
- ansible_facts.services['k3s.service'] is defined
- ansible_facts.services['k3s.service'].state == 'running'
- service_file_single.changed or service_file_ha.changed
ansible.builtin.systemd:
name: k3s
daemon_reload: true
state: restarted

- name: Enable and check K3s service
when: ansible_facts.services['k3s.service'] is not defined or ansible_facts.services['k3s.service'].state != 'running'
ansible.builtin.systemd:
name: k3s
daemon_reload: true
Expand Down Expand Up @@ -159,6 +172,7 @@
owner: root
group: root
mode: "0644"
register: service_file_ha

- name: Copy K3s service file [External DB]
when:
Expand All @@ -170,8 +184,20 @@
owner: root
group: root
mode: "0644"
register: service_file_external_db

- name: Restart K3s service
when:
- ansible_facts.services['k3s.service'] is defined
- ansible_facts.services['k3s.service'].state == 'running'
- service_file_ha.changed or service_file_external_db.changed
ansible.builtin.systemd:
name: k3s
daemon_reload: true
state: restarted

- name: Enable and check K3s service
when: ansible_facts.services['k3s.service'] is not defined or ansible_facts.services['k3s.service'].state != 'running'
ansible.builtin.systemd:
name: k3s
daemon_reload: true
Expand Down

0 comments on commit 4f76954

Please sign in to comment.