Merge 2bee1b5566 into 82bc12046b
commit
26e5456761
@ -1,17 +1,16 @@
|
||||
---
|
||||
- name: Backup Directories.
|
||||
hosts: servers
|
||||
become: true
|
||||
|
||||
pre_tasks:
|
||||
- name: Include vault variables.
|
||||
ansible.builtin.include_vars: '../{{ vault_file }}'
|
||||
ansible.builtin.include_vars: ../{{ vault_file }}
|
||||
tags: [always]
|
||||
|
||||
tasks:
|
||||
- name: Backup Directories.
|
||||
ansible.builtin.include_role:
|
||||
name: backup_directory
|
||||
with_items: "{{ backup_directories }}"
|
||||
with_items: '{{ backup_directories }}'
|
||||
loop_control:
|
||||
loop_var: backup
|
||||
|
||||
@ -1,2 +1,2 @@
|
||||
---
|
||||
# defaults file for chatton.docker_restore
|
||||
null
|
||||
...
|
||||
|
||||
@ -1,2 +1,2 @@
|
||||
---
|
||||
# handlers file for chatton.docker_restore
|
||||
null
|
||||
...
|
||||
|
||||
@ -1,121 +1,124 @@
|
||||
---
|
||||
# tasks file for chatton.docker_backup
|
||||
# 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: Get container details
|
||||
docker_container_info:
|
||||
name: "{{ container_restore }}"
|
||||
name: '{{ container_restore }}'
|
||||
register: result
|
||||
|
||||
- name: Fail if container is not present
|
||||
fail:
|
||||
msg: Cannot restore volumes for a container when it does not exist. Ensure the container exists and try again.
|
||||
msg: Cannot restore volumes for a container when it does not exist. Ensure the
|
||||
container exists and try again.
|
||||
when: result.exists == false
|
||||
|
||||
- debug: msg="{{ result }}"
|
||||
|
||||
- name: Extract only the volume mounts (not bind mounts)
|
||||
set_fact: volume_mounts="{{ result.container.Mounts | selectattr("Type", "equalto", "volume")}}"
|
||||
set_fact: volume_mounts="{{ result.container.Mounts | selectattr("Type", "equalto",
|
||||
"volume")}}"
|
||||
|
||||
- debug: msg="{{ volume_mounts }}"
|
||||
|
||||
- name: Find relevant volume(s) in S3
|
||||
amazon.aws.aws_s3:
|
||||
bucket: "{{ aws_s3.bucket }}"
|
||||
bucket: '{{ aws_s3.bucket }}'
|
||||
mode: list
|
||||
region: "{{ aws_s3.region }}"
|
||||
s3_url: "https://{{ aws_s3.s3_url }}"
|
||||
prefix: "{{ item.Name }}/{{ item.Name }}"
|
||||
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 }}
|
||||
prefix: '{{ item.Name }}/{{ item.Name }}'
|
||||
aws_access_key: '{{ aws_s3.aws_access_key }}'
|
||||
aws_secret_key: '{{ aws_s3.aws_secret_key }}'
|
||||
register: s3_list_output
|
||||
with_items: "{{ volume_mounts }}"
|
||||
with_items: '{{ volume_mounts }}'
|
||||
|
||||
- debug: msg="{{ s3_list_output }}"
|
||||
|
||||
- name: Extract s3 keys for container
|
||||
set_fact: container_s3_keys="{{ container_s3_keys | default([]) + [item.s3_keys | last] }}"
|
||||
with_items: "{{ s3_list_output.results }}"
|
||||
set_fact: container_s3_keys="{{ container_s3_keys | default([]) + [item.s3_keys
|
||||
| last] }}"
|
||||
with_items: '{{ s3_list_output.results }}'
|
||||
|
||||
- debug: msg="{{ container_s3_keys }}"
|
||||
|
||||
- name: Create a directory for temporary backups if they do not exist
|
||||
ansible.builtin.file:
|
||||
path: "/tmp/{{ item.Name }}"
|
||||
path: /tmp/{{ item.Name }}
|
||||
state: directory
|
||||
mode: '0755'
|
||||
with_items: "{{ volume_mounts }}"
|
||||
with_items: '{{ volume_mounts }}'
|
||||
|
||||
- name: Download archives from S3
|
||||
amazon.aws.aws_s3:
|
||||
bucket: "{{ aws_s3.bucket }}"
|
||||
object: "{{ item }}"
|
||||
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 }}"
|
||||
bucket: '{{ aws_s3.bucket }}'
|
||||
object: '{{ item }}'
|
||||
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 }}"
|
||||
with_items: "{{ container_s3_keys }}"
|
||||
dest: /tmp/{{ item }}
|
||||
with_items: '{{ container_s3_keys }}'
|
||||
register: get_out
|
||||
|
||||
- debug: msg="{{ get_out }}"
|
||||
|
||||
- set_fact:
|
||||
volume_details: "{{ volume_details | default([]) + [ {'mount': item.0, 's3_key': item.1} ] }}"
|
||||
volume_details: "{{ volume_details | default([]) + [ {'mount': item.0, 's3_key':\
|
||||
\ item.1} ] }}"
|
||||
with_together:
|
||||
- "{{ volume_mounts }}"
|
||||
- "{{ container_s3_keys }}"
|
||||
- '{{ volume_mounts }}'
|
||||
- '{{ container_s3_keys }}'
|
||||
|
||||
- debug: msg="{{ volume_details }}"
|
||||
|
||||
- name: Stop a container
|
||||
community.docker.docker_container:
|
||||
name: "{{ container_restore }}"
|
||||
name: '{{ container_restore }}'
|
||||
state: stopped
|
||||
|
||||
- name: Ensure Volume
|
||||
docker_volume:
|
||||
name: "{{ item.mount.Name }}"
|
||||
name: '{{ item.mount.Name }}'
|
||||
state: present
|
||||
with_items: "{{ volume_details }}"
|
||||
with_items: '{{ volume_details }}'
|
||||
|
||||
- name: Remove contents of volumes
|
||||
community.docker.docker_container:
|
||||
name: "restore-container-{{ item.mount.Name }}-{{ 10 | random }}"
|
||||
name: restore-container-{{ item.mount.Name }}-{{ 10 | random }}
|
||||
image: ubuntu
|
||||
command: "rm -rf ./* "
|
||||
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: "{{ item.mount.Destination }}"
|
||||
working_dir: '{{ item.mount.Destination }}'
|
||||
volumes:
|
||||
- /tmp:/tmp
|
||||
volumes_from:
|
||||
- "{{ container_restore }}"
|
||||
with_items: "{{ volume_details }}"
|
||||
- '{{ container_restore }}'
|
||||
with_items: '{{ volume_details }}'
|
||||
|
||||
|
||||
- name: Restore contents of volumes
|
||||
community.docker.docker_container:
|
||||
name: "restore-container-{{ item.mount.Name }}-{{ 10 | random }}"
|
||||
name: restore-container-{{ item.mount.Name }}-{{ 10 | random }}
|
||||
image: ubuntu
|
||||
# extract the tar into the volume.
|
||||
command: "tar xvf /tmp/{{ item.s3_key }}"
|
||||
command: tar xvf /tmp/{{ item.s3_key }}
|
||||
auto_remove: true
|
||||
detach: false # block until this container exists.
|
||||
state: started
|
||||
# the compressed volume contains the directories, so we start from the root
|
||||
working_dir: "/"
|
||||
working_dir: /
|
||||
volumes:
|
||||
- /tmp:/tmp
|
||||
volumes_from:
|
||||
- "{{ container_restore }}"
|
||||
with_items: "{{ volume_details }}"
|
||||
- '{{ container_restore }}'
|
||||
with_items: '{{ volume_details }}'
|
||||
|
||||
- name: Start a container
|
||||
community.docker.docker_container:
|
||||
name: "{{ container_restore }}"
|
||||
name: '{{ container_restore }}'
|
||||
state: started
|
||||
|
||||
@ -1,2 +1,2 @@
|
||||
---
|
||||
# vars file for chatton.docker_restore
|
||||
null
|
||||
...
|
||||
|
||||
@ -1,4 +1,2 @@
|
||||
# These are supported funding model platforms
|
||||
---
|
||||
github: geerlingguy
|
||||
patreon: geerlingguy
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
---
|
||||
- name: restart docker
|
||||
service:
|
||||
name: docker
|
||||
state: "{{ docker_restart_handler_state }}"
|
||||
ignore_errors: "{{ ansible_check_mode }}"
|
||||
state: '{{ docker_restart_handler_state }}'
|
||||
ignore_errors: '{{ ansible_check_mode }}'
|
||||
when: docker_service_manage | bool
|
||||
|
||||
@ -1,10 +1,9 @@
|
||||
---
|
||||
- name: Ensure docker users are added to the docker group.
|
||||
user:
|
||||
name: "{{ item }}"
|
||||
name: '{{ item }}'
|
||||
groups: docker
|
||||
append: true
|
||||
with_items: "{{ docker_users }}"
|
||||
with_items: '{{ docker_users }}'
|
||||
|
||||
- name: Reset ssh connection to apply user changes.
|
||||
meta: reset_connection
|
||||
|
||||
@ -1,2 +1 @@
|
||||
---
|
||||
docker_package: "docker"
|
||||
docker_package: docker
|
||||
|
||||
@ -1,2 +1,2 @@
|
||||
---
|
||||
# Empty file
|
||||
null
|
||||
...
|
||||
|
||||
@ -1,4 +1,2 @@
|
||||
# These are supported funding model platforms
|
||||
---
|
||||
github: geerlingguy
|
||||
patreon: geerlingguy
|
||||
|
||||
@ -1,15 +1,14 @@
|
||||
---
|
||||
- name: Ensure Pip is installed.
|
||||
package:
|
||||
name: "{{ pip_package }}"
|
||||
name: '{{ pip_package }}'
|
||||
state: present
|
||||
|
||||
- name: Ensure pip_install_packages are installed.
|
||||
pip:
|
||||
name: "{{ item.name | default(item) }}"
|
||||
version: "{{ item.version | default(omit) }}"
|
||||
virtualenv: "{{ item.virtualenv | default(omit) }}"
|
||||
state: "{{ item.state | default(omit) }}"
|
||||
extra_args: "{{ item.extra_args | default(omit) }}"
|
||||
executable: "{{ pip_executable }}"
|
||||
loop: "{{ pip_install_packages }}"
|
||||
name: '{{ item.name | default(item) }}'
|
||||
version: '{{ item.version | default(omit) }}'
|
||||
virtualenv: '{{ item.virtualenv | default(omit) }}'
|
||||
state: '{{ item.state | default(omit) }}'
|
||||
extra_args: '{{ item.extra_args | default(omit) }}'
|
||||
executable: '{{ pip_executable }}'
|
||||
loop: '{{ pip_install_packages }}'
|
||||
|
||||
@ -1,4 +1,2 @@
|
||||
# These are supported funding model platforms
|
||||
---
|
||||
github: geerlingguy
|
||||
patreon: geerlingguy
|
||||
|
||||
@ -1,3 +1,2 @@
|
||||
---
|
||||
- name: restart smb
|
||||
service: "name={{ samba_daemon }} state=restarted"
|
||||
service: name={{ samba_daemon }} state=restarted
|
||||
|
||||
@ -1,2 +1 @@
|
||||
---
|
||||
samba_daemon: smbd
|
||||
|
||||
@ -1,2 +1 @@
|
||||
---
|
||||
samba_daemon: smb
|
||||
|
||||
@ -1 +1,2 @@
|
||||
---
|
||||
null
|
||||
...
|
||||
|
||||
@ -1,12 +1,7 @@
|
||||
$ANSIBLE_VAULT;1.1;AES256
|
||||
38343033383061343739363362626366376630376337376639376235316665363736376362633830
|
||||
6638383135303063363866623262303736393337386364630a353533323537376437343033666334
|
||||
32353832353466343832643238313834616662333736363738353565623063316438393635343631
|
||||
6662366132396337320a326335353333306262666561353037356539633432376439666133386463
|
||||
30326230316634346431346266333030303435313065616665656362663164313638313639313633
|
||||
63343538653230653330383336386138643636333361326139346336646665366530343537663331
|
||||
61303639313335343162613838303034616362303935653862666166656634613562376330306165
|
||||
32373832666438623638616363363931636664633337396336653237356234616438623261353134
|
||||
62373463313235323233343734363561353237613439663534393537333964323932373837356564
|
||||
32383536613332323532633534306632373762666236366664383636323264363433396437666437
|
||||
323637336362613139633237316237666365
|
||||
$ANSIBLE_VAULT;1.1;AES256 38343033383061343739363362626366376630376337376639376235316665363736376362633830
|
||||
6638383135303063363866623262303736393337386364630a353533323537376437343033666334 32353832353466343832643238313834616662333736363738353565623063316438393635343631
|
||||
6662366132396337320a326335353333306262666561353037356539633432376439666133386463 30326230316634346431346266333030303435313065616665656362663164313638313639313633
|
||||
63343538653230653330383336386138643636333361326139346336646665366530343537663331 61303639313335343162613838303034616362303935653862666166656634613562376330306165
|
||||
32373832666438623638616363363931636664633337396336653237356234616438623261353134 62373463313235323233343734363561353237613439663534393537333964323932373837356564
|
||||
32383536613332323532633534306632373762666236366664383636323264363433396437666437 323637336362613139633237316237666365
|
||||
...
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
---
|
||||
mergerfs_prerequisites:
|
||||
- fuse
|
||||
mergerfs_dist: "{{ ansible_distribution|lower }}-{{ ansible_distribution_release }}"
|
||||
mergerfs_dist: '{{ ansible_distribution|lower }}-{{ ansible_distribution_release }}'
|
||||
mergerfs_arch_map:
|
||||
x86_64: amd64
|
||||
i386: i386
|
||||
aarch64: arm64
|
||||
armv7l: armhf
|
||||
mergerfs_arch: "{{ mergerfs_arch_map[ansible_userspace_architecture | default(ansible_architecture) ] }}"
|
||||
mergerfs_pkg_prefix: "mergerfs_"
|
||||
mergerfs_pkg_suffix: ".{{ mergerfs_dist }}_{{ mergerfs_arch }}.deb"
|
||||
mergerfs_arch: '{{ mergerfs_arch_map[ansible_userspace_architecture | default(ansible_architecture)
|
||||
] }}'
|
||||
mergerfs_pkg_prefix: mergerfs_
|
||||
mergerfs_pkg_suffix: .{{ mergerfs_dist }}_{{ mergerfs_arch }}.deb
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
---
|
||||
mergerfs_prerequisites:
|
||||
- fuse
|
||||
mergerfs_dist: "{{ 'fc' if ansible_distribution == 'Fedora' else 'el' }}{{ ansible_distribution_major_version }}"
|
||||
mergerfs_arch: "{{ ansible_userspace_architecture }}"
|
||||
mergerfs_pkg_prefix: "mergerfs-"
|
||||
mergerfs_pkg_suffix: "-1.{{ mergerfs_dist }}.{{ mergerfs_arch }}.rpm"
|
||||
mergerfs_dist: "{{ 'fc' if ansible_distribution == 'Fedora' else 'el' }}{{ ansible_distribution_major_version\
|
||||
\ }}"
|
||||
mergerfs_arch: '{{ ansible_userspace_architecture }}'
|
||||
mergerfs_pkg_prefix: mergerfs-
|
||||
mergerfs_pkg_suffix: -1.{{ mergerfs_dist }}.{{ mergerfs_arch }}.rpm
|
||||
|
||||
Loading…
Reference in New Issue