2022-04-05 11:37:27 +00:00
---
2022-07-18 13:15:04 +00:00
2022-09-27 08:38:33 +00:00
- when : matrix_backup_borg_postgresql_enabled | bool and matrix_backup_borg_version == ''
block :
2022-07-26 14:31:06 +00:00
- name : Fail with matrix_backup_borg_version advice if Postgres not enabled
ansible.builtin.fail :
msg : >-
You are not running a built-in Postgres server (`matrix_postgres_enabled : false `), so auto-detecting its version and setting `matrix_backup_borg_version` automatically based on that cannot happen.
Consider setting `matrix_backup_borg_version` to your Postgres version manually.
when : not matrix_postgres_enabled
2022-07-18 13:15:04 +00:00
- ansible.builtin.import_role :
2022-11-03 07:11:29 +00:00
name : custom/matrix-postgres
2022-07-18 13:15:04 +00:00
tasks_from : detect_existing_postgres_version
2022-04-15 16:38:10 +00:00
- name : Fail if detected Postgres version is unsupported
2022-07-18 07:39:08 +00:00
ansible.builtin.fail :
2022-04-15 16:38:10 +00:00
msg : "You cannot use borg backup with such an old version ({{ matrix_postgres_detected_version }}) of Postgres. Consider upgrading - link to docs for upgrading Postgres: docs/maintenance-postgres.md#upgrading-postgresql"
when : "matrix_postgres_detected_version not in matrix_backup_borg_supported_postgres_versions"
- name : Set the correct borg backup version to use
2022-07-18 07:39:08 +00:00
ansible.builtin.set_fact :
2022-04-15 16:43:45 +00:00
matrix_backup_borg_version : "{{ matrix_postgres_detected_version }}"
2022-04-14 15:06:54 +00:00
2022-04-05 11:37:27 +00:00
- name : Ensure borg paths exist
2022-07-18 07:39:08 +00:00
ansible.builtin.file :
2022-04-05 11:37:27 +00:00
path : "{{ item.path }}"
state : directory
mode : 0750
owner : "{{ matrix_user_username }}"
group : "{{ matrix_user_groupname }}"
with_items :
- {path : "{{ matrix_backup_borg_config_path }}" , when : true }
- {path : "{{ matrix_backup_borg_docker_src_files_path }}" , when : true }
2022-07-18 08:22:05 +00:00
when : "item.when | bool"
2022-04-05 11:37:27 +00:00
2022-04-14 15:06:54 +00:00
- name : Ensure borgmatic config is created
2022-07-18 07:39:08 +00:00
ansible.builtin.copy :
2022-07-18 08:22:05 +00:00
content : "{{ matrix_backup_borg_configuration | to_nice_yaml(indent=2, width=999999) }}"
2022-04-05 11:37:27 +00:00
dest : "{{ matrix_backup_borg_config_path }}/config.yaml"
owner : "{{ matrix_user_username }}"
group : "{{ matrix_user_groupname }}"
mode : 0640
- name : Ensure borg passwd is created
2022-07-18 07:39:08 +00:00
ansible.builtin.template :
2022-04-05 11:37:27 +00:00
src : "{{ role_path }}/templates/passwd.j2"
dest : "{{ matrix_backup_borg_config_path }}/passwd"
owner : "{{ matrix_user_username }}"
group : "{{ matrix_user_groupname }}"
mode : 0640
- name : Ensure borg ssh key is created
2022-07-18 07:39:08 +00:00
ansible.builtin.template :
2022-04-05 11:37:27 +00:00
src : "{{ role_path }}/templates/sshkey.j2"
dest : "{{ matrix_backup_borg_config_path }}/sshkey"
owner : "{{ matrix_user_username }}"
group : "{{ matrix_user_groupname }}"
mode : 0600
- name : Ensure borg image is pulled
2022-10-28 11:20:17 +00:00
community.docker.docker_image :
2022-04-05 11:37:27 +00:00
name : "{{ matrix_backup_borg_docker_image }}"
source : "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}"
force_source : "{{ matrix_backup_borg_docker_image_force_pull if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
force : "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_backup_borg_docker_image_force_pull }}"
2022-07-18 08:22:05 +00:00
when : "not matrix_backup_borg_container_image_self_build | bool"
2022-04-05 11:37:27 +00:00
register : result
retries : "{{ matrix_container_retries_count }}"
delay : "{{ matrix_container_retries_delay }}"
until : result is not failed
- name : Ensure borg repository is present on self-build
2022-07-18 07:39:08 +00:00
ansible.builtin.git :
2022-04-05 11:37:27 +00:00
repo : "{{ matrix_backup_borg_docker_repo }}"
2022-07-18 11:43:52 +00:00
version : "{{ matrix_backup_borg_docker_repo_version }}"
2022-04-05 11:37:27 +00:00
dest : "{{ matrix_backup_borg_docker_src_files_path }}"
force : "yes"
2022-04-14 05:52:37 +00:00
become : true
become_user : "{{ matrix_user_username }}"
2022-04-05 11:37:27 +00:00
register : matrix_backup_borg_git_pull_results
2022-07-18 08:22:05 +00:00
when : "matrix_backup_borg_container_image_self_build | bool"
2022-04-05 11:37:27 +00:00
- name : Ensure borg image is built
2022-10-28 11:20:17 +00:00
community.docker.docker_image :
2022-04-05 11:37:27 +00:00
name : "{{ matrix_backup_borg_docker_image }}"
source : build
force_source : "{{ matrix_backup_borg_git_pull_results.changed if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
force : "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_mailer_git_pull_results.changed }}"
build :
dockerfile : Dockerfile
path : "{{ matrix_backup_borg_docker_src_files_path }}"
pull : true
2022-07-18 08:22:05 +00:00
when : "matrix_backup_borg_container_image_self_build | bool"
2022-04-05 11:37:27 +00:00
- name : Ensure matrix-backup-borg.service installed
2022-07-18 07:39:08 +00:00
ansible.builtin.template :
2022-04-05 11:37:27 +00:00
src : "{{ role_path }}/templates/systemd/matrix-backup-borg.service.j2"
dest : "{{ matrix_systemd_path }}/matrix-backup-borg.service"
mode : 0644
register : matrix_backup_borg_systemd_service_result
- name : Ensure matrix-backup-borg.timer installed
2022-07-18 07:39:08 +00:00
ansible.builtin.template :
2022-04-05 11:37:27 +00:00
src : "{{ role_path }}/templates/systemd/matrix-backup-borg.timer.j2"
dest : "{{ matrix_systemd_path }}/matrix-backup-borg.timer"
mode : 0644
register : matrix_backup_borg_systemd_timer_result
- name : Ensure systemd reloaded after matrix-backup-borg.service installation
2022-07-18 07:39:08 +00:00
ansible.builtin.service :
2022-04-05 11:37:27 +00:00
daemon_reload : true
2022-07-18 08:22:05 +00:00
when : "matrix_backup_borg_systemd_service_result.changed | bool"
2022-04-05 11:37:27 +00:00
- name : Ensure matrix-backup-borg.service enabled
2022-07-18 07:39:08 +00:00
ansible.builtin.service :
2022-04-05 11:37:27 +00:00
enabled : true
name : matrix-backup-borg.service
- name : Ensure matrix-backup-borg.timer enabled
2022-07-18 07:39:08 +00:00
ansible.builtin.service :
2022-04-05 11:37:27 +00:00
enabled : true
name : matrix-backup-borg.timer