--- # https://docs.ansible.com/ansible/latest/collections/community/docker/docker_container_module.html#ansible-collections-community-docker-docker-container-module # https://docs.docker.com/storage/volumes/#backup-restore-or-migrate-data-volumes # - name: Download archive from S3 amazon.aws.aws_s3: bucket: "{{ aws_s3.bucket }}" object: "{{ item.s3_key }}" aws_access_key: "{{ aws_s3.aws_access_key }}" aws_secret_key: "{{ aws_s3.aws_secret_key }}" region: "{{ aws_s3.region }}" s3_url: "https://{{ aws_s3.s3_url }}" mode: get dest: "/tmp/{{ item.s3_key }}" register: get_out with_items: "{{ docker_volume_s3_restores }}" - debug: msg="{{ get_out }}" - name: Ensure Volume docker_volume: name: "{{ item.volume_name }}" state: present with_items: "{{ docker_volume_s3_restores }}" # TODO: skip if the volume was just created - name: Remove contents of volumes community.docker.docker_container: name: "restore-container-{{ item.volume_name }}-{{ 10 | random }}" image: ubuntu command: "rm -rf ./*" auto_remove: true detach: false # block until this container exists. state: started # start inside the directory we want to wipe working_dir: "/data" volumes: - "{{ item.volume_name }}:/data" with_items: "{{ docker_volume_s3_restores }}" - name: Restore contents of volumes community.docker.docker_container: name: "restore-container-{{ item.volume_name }}-{{ 10 | random }}" image: ubuntu # extract the tar into the volume. command: "tar xvf /tmp/{{ item.s3_key }} -C /data --strip-components 1" auto_remove: true detach: false # block until this container exists. state: started volumes: - "{{ item.volume_name }}:/data" - /tmp:/tmp with_items: "{{ docker_volume_s3_restores }}"