don't end play from role

pull/15/head
Cian Hatton 3 years ago
parent 13236685e8
commit ce1d9713f0

@ -11,13 +11,11 @@
- name: Determine if backup is needed. - name: Determine if backup is needed.
ansible.builtin.set_fact: should_perform_backup="{{ docker_backup_restore_force or volume_out.changed }}" 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. # try and find latest volume based on the name.
- name: Find latest s3 version. - 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: amazon.aws.aws_s3:
bucket: "{{ docker_backup_aws_s3_bucket }}" bucket: "{{ docker_backup_aws_s3_bucket }}"
mode: list mode: list
@ -30,6 +28,7 @@
- name: Fail as there no backups were found. - name: Fail as there no backups were found.
when: when:
- should_perform_backup
- docker_backup_fail_on_no_s3_backups - docker_backup_fail_on_no_s3_backups
- s3_list_output.s3_keys | length == 0 - s3_list_output.s3_keys | length == 0
ansible.builtin.fail: ansible.builtin.fail:
@ -37,19 +36,24 @@
- name: Extract S3 keys for container. - name: Extract S3 keys for container.
when: when:
- should_perform_backup
- docker_backup_restore_latest_s3_key - docker_backup_restore_latest_s3_key
- s3_list_output.s3_keys | length > 0 - s3_list_output.s3_keys | length > 0
ansible.builtin.set_fact: container_s3_key="{{ s3_list_output.s3_keys | last }}" ansible.builtin.set_fact: container_s3_key="{{ s3_list_output.s3_keys | last }}"
- name: Create directories for /tmp file. - 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: ansible.builtin.file:
path: '/tmp/{{ container_s3_key | dirname }}' path: '/tmp/{{ container_s3_key | dirname }}'
state: directory state: directory
mode: '0755' mode: '0755'
- name: Download archive from S3. - 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: amazon.aws.aws_s3:
bucket: "{{ docker_backup_aws_s3_bucket }}" bucket: "{{ docker_backup_aws_s3_bucket }}"
object: "{{ container_s3_key }}" object: "{{ container_s3_key }}"
@ -62,9 +66,11 @@
register: get_out register: get_out
- name: Remove contents of volumes. - 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: 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 image: ubuntu
command: "rm -rf ./*" command: "rm -rf ./*"
auto_remove: true auto_remove: true
@ -76,9 +82,11 @@
- "{{ docker_backup_s3_volume.name }}:/data" - "{{ docker_backup_s3_volume.name }}:/data"
- name: Restore contents of volumes - 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: 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 image: ubuntu
# extract the tar into the volume. # extract the tar into the volume.
command: "tar xvf /tmp/{{ container_s3_key }} -C /data --strip-components 1" command: "tar xvf /tmp/{{ container_s3_key }} -C /data --strip-components 1"
@ -90,7 +98,9 @@
- /tmp:/tmp - /tmp:/tmp
- name: Remove uploaded files from /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: ansible.builtin.file:
path: '/tmp/{{ container_s3_key }}' path: '/tmp/{{ container_s3_key }}'
state: absent state: absent

Loading…
Cancel
Save