From ce1d9713f0fabc85f4690c008cc95e48c728b3eb Mon Sep 17 00:00:00 2001 From: Cian Hatton Date: Thu, 8 Sep 2022 21:40:18 +0100 Subject: [PATCH] don't end play from role --- roles/docker_s3_volume_restore/tasks/main.yml | 34 ++++++++++++------- 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/roles/docker_s3_volume_restore/tasks/main.yml b/roles/docker_s3_volume_restore/tasks/main.yml index 30da928..bc36bfd 100644 --- a/roles/docker_s3_volume_restore/tasks/main.yml +++ b/roles/docker_s3_volume_restore/tasks/main.yml @@ -11,13 +11,11 @@ - name: Determine if backup is needed. ansible.builtin.set_fact: should_perform_backup="{{ docker_backup_restore_force or volume_out.changed }}" -- name: End play as no backup is needed. - ansible.builtin.meta: end_play - when: not should_perform_backup - # try and find latest volume based on the name. - name: Find latest s3 version. - when: docker_backup_restore_latest_s3_key + when: + - should_perform_backup + - docker_backup_restore_latest_s3_key amazon.aws.aws_s3: bucket: "{{ docker_backup_aws_s3_bucket }}" mode: list @@ -30,6 +28,7 @@ - name: Fail as there no backups were found. when: + - should_perform_backup - docker_backup_fail_on_no_s3_backups - s3_list_output.s3_keys | length == 0 ansible.builtin.fail: @@ -37,19 +36,24 @@ - name: Extract S3 keys for container. when: + - should_perform_backup - docker_backup_restore_latest_s3_key - s3_list_output.s3_keys | length > 0 ansible.builtin.set_fact: container_s3_key="{{ s3_list_output.s3_keys | last }}" - name: Create directories for /tmp file. - when: s3_list_output.s3_keys | length > 0 + when: + - should_perform_backup + - s3_list_output.s3_keys | length > 0 ansible.builtin.file: path: '/tmp/{{ container_s3_key | dirname }}' state: directory mode: '0755' - name: Download archive from S3. - when: s3_list_output.s3_keys | length > 0 + when: + - should_perform_backup + - s3_list_output.s3_keys | length > 0 amazon.aws.aws_s3: bucket: "{{ docker_backup_aws_s3_bucket }}" object: "{{ container_s3_key }}" @@ -62,9 +66,11 @@ register: get_out - name: Remove contents of volumes. - when: s3_list_output.s3_keys | length > 0 + when: + - should_perform_backup + - s3_list_output.s3_keys | length > 0 community.docker.docker_container: - name: "restore-container-{{ docker_backup_s3_volume.name }}-{{ 10 | random }}" + name: "restore-container-{{ docker_backup_s3_volume.name }}-{{ 100 | random }}" image: ubuntu command: "rm -rf ./*" auto_remove: true @@ -76,9 +82,11 @@ - "{{ docker_backup_s3_volume.name }}:/data" - name: Restore contents of volumes - when: s3_list_output.s3_keys | length > 0 + when: + - should_perform_backup + - s3_list_output.s3_keys | length > 0 community.docker.docker_container: - name: "restore-container-{{ docker_backup_s3_volume.name }}-{{ 10 | random }}" + name: "restore-container-{{ docker_backup_s3_volume.name }}-{{ 100 | random }}" image: ubuntu # extract the tar into the volume. command: "tar xvf /tmp/{{ container_s3_key }} -C /data --strip-components 1" @@ -90,7 +98,9 @@ - /tmp:/tmp - name: Remove uploaded files from /tmp - when: s3_list_output.s3_keys | length > 0 + when: + - should_perform_backup + - s3_list_output.s3_keys | length > 0 ansible.builtin.file: path: '/tmp/{{ container_s3_key }}' state: absent