You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

69 lines
2.2 KiB
YAML

- name: Create a directory if it does not exist
ansible.builtin.file:
path: "{{docker_compose_directory}}/{{item.name}}"
state: directory
mode: '0755'
with_items: "{{services}}"
- name: Copy Docker Compose Files
copy:
src: "{{item.name}}/docker-compose.yml"
dest: "{{docker_compose_directory}}/{{item.name}}/docker-compose.yml"
with_items: "{{services}}"
- name: Install python dependencies (requests)
ansible.builtin.pip:
name: requests
- name: Find docker volumes
shell: docker volume ls -f name={{item.name}} --format '{{ '{{' }} .Name {{ '}}' }}'
with_items: "{{services}}"
register: find_volumes
changed_when: False
- debug: msg="{{find_volumes.results | map(attribute='stdout_lines') | list | flatten }}"
- name: Find volumes that need to be restored
script: scripts/find-volumes-to-restore.py
environment:
EXISTING_VOLUMES: "{{ find_volumes.results | map(attribute='stdout_lines') | list | flatten }}"
SERVICES: "{{ services }}"
args:
executable: python3
register: python_output
changed_when: False
- debug: msg="{{python_output.stdout_lines | list }}"
- name: Restore any missing backups from S3
docker_container:
command: "restore-volume --s3 --volume {{item}}"
image: "ghcr.io/chatton/docker-volume-backup:v0.3.0"
name: "s3-restore-{{item}}"
cleanup: true # delete container after it's done.
state: started # container should execute.
detach: no # task fails if container exits.
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- /tmp:/tmp # temp s3 archive goes here
env:
AWS_ACCESS_KEY_ID: "{{aws_s3.aws_access_key}}"
AWS_SECRET_ACCESS_KEY: "{{aws_s3_secrets.aws_secret_key}}"
AWS_DEFAULT_REGION: "{{aws_s3.region}}"
AWS_BUCKET: "{{aws_s3.bucket}}"
AWS_ENDPOINT: "{{aws_s3.s3_url}}"
with_items: "{{ python_output.stdout_lines }}"
- name: Create required docker networks
docker_network:
name: "{{item}}"
with_items: "{{ docker_networks }}"
- name: Update Portainer Stack
portainer:
username: admin
password: "{{portainer.password}}"
docker_compose_file_path: "{{docker_compose_directory}}/{{ item.name }}/docker-compose.yml"
stack_name: "{{ item.name }}"
with_items: "{{services}}"