Skip to content

Commit

Permalink
Cleanup old Nextcloud version directories except the last four
Browse files Browse the repository at this point in the history
Fixes: #80
  • Loading branch information
doobry-systemli committed Oct 1, 2024
1 parent 9fa92dd commit 7d7035c
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 1 deletion.
4 changes: 4 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,7 @@ nextcloud_notify_push_max_connection_time: False
nextcloud_notify_push_port: 7867
# Uncomment to expose Nextcloud notify_push metrics
# nextcloud_notify_push_metrics_port: 7868

# Cleanup old nextcloud version folders
nextcloud_cleanup_versions: True
nextcloud_cleanup_versions_keep: 4
7 changes: 7 additions & 0 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,13 @@
- role:nextcloud:install
- role:nextcloud:upgrade

- name: Cleanup old Nextcloud version folders
ansible.builtin.import_tasks: nextcloud/cleanup-versions.yml
when: nextcloud_cleanup_versions
tags:
- role:nextcloud:upgrade
- role:nextcloud:cleanup

- name: Setup Nextcloud push notification daemon
ansible.builtin.include_tasks: nextcloud/notify-push.yml
when: nextcloud_notify_push
Expand Down
21 changes: 21 additions & 0 deletions tasks/nextcloud/cleanup-versions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---

- name: Get link destination of nextcloud_symlink
ansible.builtin.stat:
path: "{{ nextcloud_symlink }}"
register: __nextcloud_symlink

- name: Find old version directories in nextcloud_workdir
ansible.builtin.find:
paths: "{{ nextcloud_workdir }}"
file_type: directory
excludes: "{{ __nextcloud_symlink.stat.lnk_target }},nextcloud-{{ nextcloud_version }}"
patterns: '^nextcloud-[0-9]+\.[0-9]+\.[0-9]+$'
use_regex: True
register: __nextcloud_version_folders

- name: "Remove old version directories except last {{ nextcloud_cleanup_versions_keep }}"
ansible.builtin.file:
path: "{{ item }}"
state: absent
loop: "{{ (__nextcloud_version_folders | json_query('files[].path') | sort)[:-nextcloud_cleanup_versions_keep] }}"
2 changes: 1 addition & 1 deletion tasks/nextcloud/configure.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
- "{{ nextcloud_custom_apps }}"

- name: "Nextcloud configure: enable custom apps"
become: true
become: True
become_user: "{{ nextcloud_http_user }}"
nextcloud_app:
name: "{{ item }}"
Expand Down

0 comments on commit 7d7035c

Please sign in to comment.