ansible-role-borg-backup/tasks/main.yml

133 lines
3.9 KiB
YAML
Raw Normal View History

2018-10-06 14:04:20 +02: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.
- 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: Run OS-specific tasks
include_tasks: "{{ item }}"
with_first_found:
- "{{ ansible_os_family }}-{{ ansible_distribution_major_version }}.yml"
- "{{ ansible_os_family }}.yml"
2018-10-06 14:04:20 +02:00
- name: Install required System Packages
package:
name: "{{ borg_packages }}"
state: present
2018-10-06 14:04:20 +02:00
- name: Create virtualenv for borg # noqa package-latest
pip:
name:
- pip
- setuptools
state: latest
virtualenv: /opt/borgmatic
virtualenv_command: "{{ python_bin }} -m venv"
- name: Install dependent Python Packages
pip:
name: "{{ borg_dependent_python_packages }}"
virtualenv: /opt/borgmatic
when: borg_dependent_python_packages is defined
- name: Install main Python Packages
2018-10-06 14:04:20 +02:00
pip:
name: "{{ item.name }}"
version: "{{ item.version | default(omit, true) }}"
virtualenv: /opt/borgmatic
when: borg_python_packages is defined
loop: "{{ borg_python_packages }}"
2018-10-06 14:04:20 +02:00
- name: Create borgmatic command in /usr/local/bin
copy:
content: |
#!/bin/bash
. /opt/borgmatic/bin/activate
borgmatic "$@"
dest: /usr/local/bin/borgmatic
owner: root
group: root
mode: "0755"
2018-10-06 14:04:20 +02:00
- name: Ensure root has SSH key.
user:
name: "root"
generate_ssh_key: yes
ssh_key_file: "{{ ssh_key_file }}"
2018-10-06 14:04:20 +02:00
ssh_key_type: ed25519
register: root_user
- 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']
- name: Ensure /etc/borgmatic exists
2018-10-06 14:04:20 +02:00
file:
path: /etc/borgmatic
2018-10-06 14:04:20 +02:00
state: directory
mode: 0700
owner: root
- name: Add Borgmatic configuration
2018-10-06 14:04:20 +02:00
template:
src: config.yaml.j2
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)
block:
- name: Add cron job for regular create and prune
cron:
name: "{{ borgmatic_cron_name }}"
hour: "{{ borgmatic_cron_hour }}"
minute: "{{ borgmatic_cron_minute }}"
2019-05-15 06:44:10 +02:00
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 }}"
2019-05-15 06:44:10 +02:00
user: "root"
cron_file: "{{ borgmatic_cron_name }}"
job: "borgmatic -c /etc/borgmatic/{{ borgmatic_config_name }} -k"
when: borgmatic_large_repo
- name: Add cron-job for borgmatic (normal-sized repo)
2019-05-15 06:44:10 +02:00
block:
- name: Add cron job for create, check and prune
cron:
name: "{{ borgmatic_cron_name }}"
hour: "{{ borgmatic_cron_hour }}"
minute: "{{ borgmatic_cron_minute }}"
2019-05-15 06:44:10 +02:00
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"
2019-05-15 06:44:10 +02:00
state: absent
when: not borgmatic_large_repo
2018-10-11 09:08:57 +02:00
- name: Set PATH for borgmatic cron job.
cron:
user: "root"
cron_file: "{{ borgmatic_cron_name }}"
2018-10-11 09:08:57 +02:00
name: PATH
env: yes
value: /usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin