Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions roles/_init/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,5 @@ mautic:
image_path: "media/images"
force_install: false
bin_directory: "/home/{{ deploy_user }}/.bin"
# Number of dumps/db to look up for cleanup.
cleanup_history_depth: 50
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
ansible.builtin.file:
path: "{{ mysql_backup.dumps_directory }}/{{ _mysql_host }}/{{ database.database }}-{{ item }}.sql.bz2"
state: absent
with_sequence: start={{ [previous_build_number | int - 50, 0] | max }} end={{ [previous_build_number | int - mysql_backup.keep, 0] | max }}
with_sequence: start={{ [previous_build_number | int - cleanup_history_depth, 0] | max }} end={{ [previous_build_number | int - mysql_backup.keep, 0] | max }}
run_once: true
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
---
# We assume it's safe to only go back 50 build back.
- name: Delete mysql databases.
community.mysql.mysql_db:
name: "{{ database.database }}_{{ item }}"
state: absent
login_host: "{{ _mysql_host }}"
login_user: "{{ _mysql_user }}"
login_password: "{{ _mysql_password }}"
with_sequence: start={{ [previous_build_number | int - 50, 0] | max }} end={{ [previous_build_number | int - mysql_backup.keep, 0] | max }}
with_sequence: start={{ [previous_build_number | int - cleanup_history_depth, 0] | max }} end={{ [previous_build_number | int - mysql_backup.keep, 0] | max }}
run_once: true
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

- ansible.builtin.include_tasks: "cleanup-{{ mysql_backup.handling }}.yml"

# We assume it's safe to only go back 50 build back.
- name: Delete mysql users.
community.mysql.mysql_user:
name: "{{ database.user }}_{{ item }}"
Expand All @@ -24,6 +23,6 @@
login_host: "{{ _mysql_host }}"
login_user: "{{ _mysql_user }}"
login_password: "{{ _mysql_password }}"
with_sequence: start={{ [previous_build_number | int - 50, 0] | max }} end={{ [previous_build_number | int - mysql_backup.keep, 0] | max }}
with_sequence: start={{ [previous_build_number | int - cleanup_history_depth, 0] | max }} end={{ [previous_build_number | int - mysql_backup.keep, 0] | max }}
when: mysql_backup.credentials_handling == 'rotate'
run_once: true
10 changes: 5 additions & 5 deletions roles/deploy_code/tasks/cleanup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
- name: Ensure codebase is writable.
ansible.builtin.shell:
cmd: "if [ -d {{ deploy_path_prefix }}{{ item }} ]; then chmod -R 777 {{ deploy_path_prefix }}{{ item }}; fi"
with_sequence: start={{ [previous_build_number | int - 50, 0] | max }} end={{ [previous_build_number | int - deploy_code.keep, 0] | max }}
with_sequence: start={{ [previous_build_number | int - cleanup_history_depth, 0] | max }} end={{ [previous_build_number | int - deploy_code.keep, 0] | max }}
become: true
when: "www_user != deploy_user"

- name: Ensure permissions are set on deploy directory.
ansible.builtin.shell:
cmd: "if [ -d {{ deploy_path_prefix }}{{ item }}/{{ deploy_code.perms_fix_path }} ]; then chmod 755 {{ deploy_path_prefix }}{{ item }}/{{ deploy_code.perms_fix_path }}; fi"
with_sequence: start={{ [previous_build_number | int - 50, 0] | max }} end={{ [previous_build_number | int - deploy_code.keep, 0] | max }}
with_sequence: start={{ [previous_build_number | int - cleanup_history_depth, 0] | max }} end={{ [previous_build_number | int - deploy_code.keep, 0] | max }}
when:
- deploy_code.perms_fix_path is defined
- deploy_code.perms_fix_path | length > 1
Expand All @@ -18,7 +18,7 @@
- name: Ensure permissions are set on builds directory.
ansible.builtin.shell:
cmd: "if [ -d {{ build_path_prefix }}{{ item }}/{{ deploy_code.perms_fix_path }} ]; then chmod 755 {{ build_path_prefix }}{{ item }}/{{ deploy_code.perms_fix_path }}; fi"
with_sequence: start={{ [previous_build_number | int - 50, 0] | max }} end={{ [previous_build_number | int - deploy_code.keep, 0] | max }}
with_sequence: start={{ [previous_build_number | int - cleanup_history_depth, 0] | max }} end={{ [previous_build_number | int - deploy_code.keep, 0] | max }}
when:
- deploy_code.perms_fix_path is defined
- deploy_code.perms_fix_path | length > 1
Expand All @@ -28,15 +28,15 @@
ansible.builtin.file:
name: "{{ deploy_path_prefix }}{{ item }}"
state: absent
with_sequence: start={{ [previous_build_number | int - 50, 0] | max }} end={{ [previous_build_number | int - deploy_code.keep, 0] | max }}
with_sequence: start={{ [previous_build_number | int - cleanup_history_depth, 0] | max }} end={{ [previous_build_number | int - deploy_code.keep, 0] | max }}
when:
- deploy_code.mount_type != "squashfs"

- name: Delete codebases from builds directory.
ansible.builtin.file:
name: "{{ build_path_prefix }}{{ item }}"
state: absent
with_sequence: start={{ [previous_build_number | int - 50, 0] | max }} end={{ [previous_build_number | int - deploy_code.keep, 0] | max }}
with_sequence: start={{ [previous_build_number | int - cleanup_history_depth, 0] | max }} end={{ [previous_build_number | int - deploy_code.keep, 0] | max }}
when:
- deploy_code.mount_type == "squashfs"

Expand Down