mirror of
https://github.com/borgbase/ansible-role-borgbackup.git
synced 2024-11-19 19:07:42 +01:00
97 lines
3.0 KiB
YAML
Executable File
97 lines
3.0 KiB
YAML
Executable File
---
|
|
- 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.
|
|
|
|
- name: Include OS-specific variables
|
|
include_vars: "{{ item }}"
|
|
with_first_found:
|
|
- "{{ ansible_distribution }}-{{ ansible_distribution_major_version }}.yml"
|
|
- "{{ ansible_os_family }}-{{ ansible_distribution_major_version }}.yml"
|
|
- "{{ ansible_distribution }}.yml"
|
|
- "{{ ansible_os_family }}.yml"
|
|
- "{{ ansible_lsb.id }}.yml"
|
|
|
|
- name: Install general dependencies (cron and openssh)
|
|
package:
|
|
name: "{{ borg_dep_packages }}"
|
|
state: present
|
|
|
|
- name: Install Borg and Borgmatic
|
|
ansible.builtin.include_tasks:
|
|
file: install_{{ borg_install_method }}.yml
|
|
|
|
- name: Ensure root has SSH key.
|
|
user:
|
|
name: "root"
|
|
generate_ssh_key: yes
|
|
ssh_key_file: "{{ ssh_key_file }}"
|
|
ssh_key_type: ed25519
|
|
register: root_user
|
|
|
|
- name: Print key created for root user (use for remote repo)
|
|
debug:
|
|
var: root_user['ssh_public_key']
|
|
|
|
- name: Ensure /etc/borgmatic exists
|
|
file:
|
|
path: /etc/borgmatic
|
|
state: directory
|
|
mode: 0700
|
|
owner: root
|
|
|
|
- name: Add Borgmatic configuration
|
|
template:
|
|
src: config.yaml.j2
|
|
dest: "/etc/borgmatic/{{ borgmatic_config_name }}"
|
|
mode: 0600
|
|
|
|
- name: Add cron-job for borgmatic (large repo, create and check separate)
|
|
when: borgmatic_large_repo
|
|
block:
|
|
- name: Add cron job for regular create and prune
|
|
cron:
|
|
name: "{{ borgmatic_cron_name }}"
|
|
hour: "{{ borgmatic_cron_hour }}"
|
|
minute: "{{ borgmatic_cron_minute }}"
|
|
user: "root"
|
|
cron_file: "{{ borgmatic_cron_name }}"
|
|
job: "borgmatic -c /etc/borgmatic/{{ borgmatic_config_name }} -C -p"
|
|
- name: Add cron job for infrequent checks
|
|
cron:
|
|
name: "{{ borgmatic_cron_name }}-check"
|
|
day: "{{ borgmatic_cron_checks_day }}"
|
|
hour: "{{ borgmatic_cron_checks_hour }}"
|
|
minute: "{{ borgmatic_cron_checks_minute }}"
|
|
user: "root"
|
|
cron_file: "{{ borgmatic_cron_name }}"
|
|
job: "borgmatic -c /etc/borgmatic/{{ borgmatic_config_name }} -k"
|
|
|
|
- name: Add cron-job for borgmatic (normal-sized repo)
|
|
when: not borgmatic_large_repo
|
|
block:
|
|
- name: Add cron job for create, check and prune
|
|
cron:
|
|
name: "{{ borgmatic_cron_name }}"
|
|
hour: "{{ borgmatic_cron_hour }}"
|
|
minute: "{{ borgmatic_cron_minute }}"
|
|
user: "root"
|
|
cron_file: "{{ borgmatic_cron_name }}"
|
|
job: "borgmatic -c /etc/borgmatic/{{ borgmatic_config_name }}"
|
|
- name: Ensure separate check cron job is absent
|
|
cron:
|
|
name: "{{ borgmatic_cron_name }}-check"
|
|
state: absent
|
|
|
|
- name: Set PATH for borgmatic cron job.
|
|
cron:
|
|
user: "root"
|
|
cron_file: "{{ borgmatic_cron_name }}"
|
|
name: PATH
|
|
env: yes
|
|
value: /usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
|