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

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

Merged
Merged
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
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
Loading