2018-10-06 14:04:20 +02:00
|
|
|
---
|
2022-02-20 11:42:09 +01:00
|
|
|
- name: Ensure legacy hooks aren't used
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- borgmatic_failure_command is undefined
|
|
|
|
- borgmatic_before_backup_command is undefined
|
|
|
|
- borgmatic_after_backup_command is undefined
|
|
|
|
msg: Please use the new borgmatic_hooks variable instead of individual before/after/failure hooks.
|
|
|
|
|
2020-02-17 17:21:21 +01:00
|
|
|
- name: Include OS-specific variables
|
2020-02-18 07:35:20 +01:00
|
|
|
include_vars: "{{ item }}"
|
|
|
|
with_first_found:
|
2020-09-22 12:32:44 +02:00
|
|
|
- "{{ ansible_distribution }}-{{ ansible_distribution_major_version }}.yml"
|
2020-02-18 07:35:20 +01:00
|
|
|
- "{{ ansible_os_family }}-{{ ansible_distribution_major_version }}.yml"
|
2020-09-22 12:32:44 +02:00
|
|
|
- "{{ ansible_distribution }}.yml"
|
2020-02-18 07:35:20 +01:00
|
|
|
- "{{ ansible_os_family }}.yml"
|
2021-04-20 08:53:35 +02:00
|
|
|
- "{{ ansible_lsb.id }}.yml"
|
2020-02-17 17:21:21 +01:00
|
|
|
|
2022-12-15 17:40:53 +01:00
|
|
|
- name: Install general dependencies (cron and openssh)
|
2019-10-24 07:05:19 +02:00
|
|
|
package:
|
2022-12-15 17:40:53 +01:00
|
|
|
name: "{{ borg_dep_packages }}"
|
2019-09-23 18:30:22 +02:00
|
|
|
state: present
|
2018-10-06 14:04:20 +02:00
|
|
|
|
2022-12-15 17:40:53 +01:00
|
|
|
- name: Install Borg and Borgmatic
|
|
|
|
ansible.builtin.include_tasks:
|
|
|
|
file: install_{{ borg_install_method }}.yml
|
2021-06-21 19:58:51 +02:00
|
|
|
|
2018-10-06 14:04:20 +02:00
|
|
|
- name: Ensure root has SSH key.
|
|
|
|
user:
|
|
|
|
name: "root"
|
|
|
|
generate_ssh_key: yes
|
2020-01-29 08:29:33 +01:00
|
|
|
ssh_key_file: "{{ ssh_key_file }}"
|
2018-10-06 14:04:20 +02:00
|
|
|
ssh_key_type: ed25519
|
|
|
|
register: root_user
|
|
|
|
|
2021-04-20 08:53:35 +02:00
|
|
|
- name: Print key created for root user (use for remote repo)
|
|
|
|
debug:
|
2018-10-06 14:04:20 +02:00
|
|
|
var: root_user['ssh_public_key']
|
2020-02-17 17:21:21 +01:00
|
|
|
|
2022-02-20 10:56:14 +01:00
|
|
|
- name: Ensure /etc/borgmatic exists
|
2018-10-06 14:04:20 +02:00
|
|
|
file:
|
2020-02-17 17:21:21 +01:00
|
|
|
path: /etc/borgmatic
|
2018-10-06 14:04:20 +02:00
|
|
|
state: directory
|
|
|
|
mode: 0700
|
|
|
|
owner: root
|
|
|
|
|
2022-02-20 10:56:14 +01:00
|
|
|
- name: Add Borgmatic configuration
|
2018-10-06 14:04:20 +02:00
|
|
|
template:
|
|
|
|
src: config.yaml.j2
|
2020-02-17 17:21:21 +01:00
|
|
|
dest: "/etc/borgmatic/{{ borgmatic_config_name }}"
|
2018-10-06 14:04:20 +02:00
|
|
|
mode: 0600
|
|
|
|
|
2019-05-15 06:44:10 +02:00
|
|
|
- name: Add cron-job for borgmatic (large repo, create and check separate)
|
2023-03-19 11:19:47 +01:00
|
|
|
when: borgmatic_large_repo
|
2019-05-15 06:44:10 +02:00
|
|
|
block:
|
2020-02-17 17:21:21 +01:00
|
|
|
- name: Add cron job for regular create and prune
|
|
|
|
cron:
|
2021-02-17 03:16:34 +01:00
|
|
|
name: "{{ borgmatic_cron_name }}"
|
2020-07-15 05:40:38 +02:00
|
|
|
hour: "{{ borgmatic_cron_hour }}"
|
|
|
|
minute: "{{ borgmatic_cron_minute }}"
|
2019-05-15 06:44:10 +02:00
|
|
|
user: "root"
|
2021-02-17 03:16:34 +01:00
|
|
|
cron_file: "{{ borgmatic_cron_name }}"
|
2022-09-03 11:07:50 +02:00
|
|
|
job: "borgmatic -c /etc/borgmatic/{{ borgmatic_config_name }} -C -p"
|
2020-02-17 17:21:21 +01:00
|
|
|
- name: Add cron job for infrequent checks
|
|
|
|
cron:
|
2021-02-17 03:16:34 +01:00
|
|
|
name: "{{ borgmatic_cron_name }}-check"
|
2020-07-15 05:40:38 +02:00
|
|
|
day: "{{ borgmatic_cron_checks_day }}"
|
|
|
|
hour: "{{ borgmatic_cron_checks_hour }}"
|
|
|
|
minute: "{{ borgmatic_cron_checks_minute }}"
|
2019-05-15 06:44:10 +02:00
|
|
|
user: "root"
|
2021-02-17 03:16:34 +01:00
|
|
|
cron_file: "{{ borgmatic_cron_name }}"
|
2022-09-03 11:07:50 +02:00
|
|
|
job: "borgmatic -c /etc/borgmatic/{{ borgmatic_config_name }} -k"
|
2019-05-01 04:39:07 +02:00
|
|
|
|
|
|
|
- name: Add cron-job for borgmatic (normal-sized repo)
|
2023-03-19 11:19:47 +01:00
|
|
|
when: not borgmatic_large_repo
|
2019-05-15 06:44:10 +02:00
|
|
|
block:
|
2020-02-17 17:21:21 +01:00
|
|
|
- name: Add cron job for create, check and prune
|
|
|
|
cron:
|
2021-02-17 03:16:34 +01:00
|
|
|
name: "{{ borgmatic_cron_name }}"
|
2020-07-15 05:40:38 +02:00
|
|
|
hour: "{{ borgmatic_cron_hour }}"
|
|
|
|
minute: "{{ borgmatic_cron_minute }}"
|
2019-05-15 06:44:10 +02:00
|
|
|
user: "root"
|
2021-02-17 03:16:34 +01:00
|
|
|
cron_file: "{{ borgmatic_cron_name }}"
|
2021-06-22 08:36:26 +02:00
|
|
|
job: "borgmatic -c /etc/borgmatic/{{ borgmatic_config_name }}"
|
2020-02-17 17:21:21 +01:00
|
|
|
- name: Ensure separate check cron job is absent
|
|
|
|
cron:
|
2021-02-17 03:16:34 +01:00
|
|
|
name: "{{ borgmatic_cron_name }}-check"
|
2019-05-15 06:44:10 +02:00
|
|
|
state: absent
|
2018-10-11 09:08:57 +02:00
|
|
|
|
|
|
|
- name: Set PATH for borgmatic cron job.
|
|
|
|
cron:
|
|
|
|
user: "root"
|
2021-02-17 03:16:34 +01:00
|
|
|
cron_file: "{{ borgmatic_cron_name }}"
|
2018-10-11 09:08:57 +02:00
|
|
|
name: PATH
|
|
|
|
env: yes
|
2018-10-29 04:27:25 +01:00
|
|
|
value: /usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
|