diff --git a/roles/deploy_code/tasks/cleanup.yml b/roles/deploy_code/tasks/cleanup.yml index 5ca473bf..3336b22f 100644 --- a/roles/deploy_code/tasks/cleanup.yml +++ b/roles/deploy_code/tasks/cleanup.yml @@ -29,6 +29,16 @@ - deploy_code.mount_type == "tarball" run_once: true +- name: Ensure older SquashFS images are deleted. + ansible.builtin.file: + path: "{{ build_base_path }}/deploy.sqsh" + state: absent + when: + - deploy_code.mount_sync is defined + - deploy_code.mount_sync | length > 1 + - deploy_code.mount_type == "squashfs" + run_once: true + - name: Create a SquashFS image of the deployed codebases. ansible.builtin.command: cmd: "mksquashfs {{ build_base_path }} /tmp/{{ project_name }}_{{ build_type }}.sqsh" @@ -74,15 +84,26 @@ - deploy_code.mount_sync | length > 1 - deploy_code.mount_type == "squashfs" -- name: Unmount existing SquashFS image. +- name: Check if we have a mount already. + ansible.builtin.command: + cmd: "mount | grep {{ deploy_base_path }}" + ignore_errors: true + register: _mount_check + when: + - deploy_code.mount_sync is defined + - deploy_code.mount_sync | length > 1 + - deploy_code.mount_type == "squashfs" + +- name: Remount existing SquashFS image. ansible.builtin.command: - cmd: "umount --force {{ deploy_base_path }}" + cmd: "mount {{ build_base_path }}/deploy.sqsh {{ deploy_base_path }} -t squashfs -o remount" become: true become_user: "{{ deploy_user }}" when: - deploy_code.mount_sync is defined - deploy_code.mount_sync | length > 1 - deploy_code.mount_type == "squashfs" + - _mount_check | success - name: Mount new SquashFS image. ansible.builtin.command: @@ -93,6 +114,7 @@ - deploy_code.mount_sync is defined - deploy_code.mount_sync | length > 1 - deploy_code.mount_type == "squashfs" + - _mount_check | failed - name: Trigger an infrastructure rebuild. ansible.builtin.include_role: