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