Skip to content

Commit

Permalink
remote: improved cleanup logic
Browse files Browse the repository at this point in the history
  • Loading branch information
saltydk committed Aug 28, 2023
1 parent 60d86c8 commit a0ec8c1
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 3 additions & 0 deletions roles/remote/tasks/cleanup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- name: "Cleanup | Set 'rclone_service_name'"
ansible.builtin.set_fact:
rclone_service_name: "{{ item.split('.')[0] }}"
rclone_service_name_full: "{{ item.split('.')[0] }}.service"
rclone_refresh_service_name: "{{ item.split('.')[0] }}_refresh.service"

- name: "Cleanup | Fail if 'rclone_service_name' is empty"
Expand All @@ -22,11 +23,13 @@
name: "{{ rclone_service_name }}.service"
state: stopped
enabled: false
when: rclone_service_name_full in saltbox_managed_rclone_services

- name: "Cleanup | Delete '{{ rclone_service_name }}.service'"
ansible.builtin.file:
path: "/etc/systemd/system/{{ rclone_service_name }}.service"
state: absent
when: rclone_service_name_full in saltbox_managed_rclone_services

- name: "Cleanup | Stop and disable existing '{{ rclone_refresh_service_name }}'"
ansible.builtin.systemd:
Expand Down
2 changes: 1 addition & 1 deletion roles/remote/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@
loop: "{{ services | dict2items }}"
loop_control:
loop_var: rclone_service
when: (rclone_service_template in rclone_service.key)
when: (rclone_service_template in rclone_service.key) and (rclone_service.value.status != 'not-found')

- name: Cleanup Tasks
ansible.builtin.include_tasks: "cleanup.yml"
Expand Down

0 comments on commit a0ec8c1

Please sign in to comment.