diff --git a/defaults/main.yml b/defaults/main.yml index 3b7e964..e333fe5 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -290,3 +290,10 @@ magento_upgrade_commands: magento_run_message_queue_consumers_separately: false magento_queue_consumers_cron_template: "/usr/bin/php {{ magento_app_root }}/bin/magento queue:consumers:start {{ item.name }}" + +## Deletes all installed deployable magento packages except the +## %magento_clones_to_keep% amount of latest ones + all that are newer than +## %magento_clones_cleanup_min_age% +magento_cleanup_old_clones: True +magento_clones_to_keep: 5 +magento_clones_cleanup_min_age: "1d" diff --git a/tasks/cleanup-old-clones.yml b/tasks/cleanup-old-clones.yml new file mode 100644 index 0000000..0b7ead3 --- /dev/null +++ b/tasks/cleanup-old-clones.yml @@ -0,0 +1,15 @@ +--- +- name: "Discover old clone/release directories which need to be cleaned" + find: + paths: "{{ magento_release_folder }}" + age: "{{ magento_clones_cleanup_min_age }}" + file_type: directory + age_stamp: "ctime" + register: magento_clones_for_cleanup + +- name: "Remove old clones/releases" + file: + path: "{{ item.path }}" + state: absent + when: magento_cleanup_old_clones == True + with_items: "{{ (magento_clones_for_cleanup.files | sort(attribute='ctime', reverse=True))[magento_clones_to_keep:] | list }}" diff --git a/tasks/main.yml b/tasks/main.yml index 8f327bd..76f8ab9 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -3,4 +3,5 @@ - include: "setup.yml" - include: "installation.yml" - include: "message-queue-consumers.yml" +- include: "cleanup-old-clones.yml" - include: "admin.yml"