Skip to content

Commit

Permalink
Keep service backups under /etc/systemd/system (#324)
Browse files Browse the repository at this point in the history
Signed-off-by: laszlojau <[email protected]>
  • Loading branch information
laszlojau authored Apr 5, 2024
1 parent 33c15e7 commit 7ec16a8
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions roles/k3s_upgrade/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,20 @@
- name: Update node only if needed
when: installed_k3s_version is version(k3s_version, '<')
block:
- name: Find K3s service files
ansible.builtin.find:
paths: "{{ systemd_dir }}"
patterns: "k3s*.service"
register: k3s_service_files

- name: Save current K3s service
ansible.builtin.shell:
cmd: "cp {{ systemd_dir }}/k3s*.service /tmp/"
changed_when: true
ansible.builtin.copy:
src: "{{ item.path }}"
dest: "{{ item.path }}.bak"
remote_src: true
mode: preserve
force: true
loop: "{{ k3s_service_files.files }}"

- name: Install new K3s Version
ansible.builtin.command:
Expand All @@ -29,9 +39,19 @@
changed_when: true

- name: Restore K3s service
ansible.builtin.shell:
cmd: "mv /tmp/k3s*.service {{ systemd_dir }}/"
changed_when: true
ansible.builtin.copy:
src: "{{ item.path }}.bak"
dest: "{{ item.path }}"
remote_src: true
mode: preserve
force: true
loop: "{{ k3s_service_files.files }}"

- name: Clean up temporary K3s service backups
ansible.builtin.file:
path: "{{ item.path }}.bak"
state: absent
loop: "{{ k3s_service_files.files }}"

- name: Restart K3s service [server]
when: "'server' in group_names"
Expand Down

0 comments on commit 7ec16a8

Please sign in to comment.