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
|
|
|
|
2021-04-20 08:53:35 +02:00
|
|
|
- name: Run OS-specific tasks
|
2020-02-18 07:35:20 +01:00
|
|
|
include: "{{ 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
|
2019-10-24 07:05:19 +02:00
|
|
|
package:
|
2020-11-27 00:46:55 +01:00
|
|
|
name: "{{ borg_packages }}"
|
2019-09-23 18:30:22 +02:00
|
|
|
state: present
|
2018-10-06 14:04:20 +02:00
|
|
|
|
2022-03-06 07:01:25 +01:00
|
|
|
- name: Create virtualenv for borg # noqa package-latest
|
2019-10-24 07:05:19 +02:00
|
|
|
pip:
|
2022-03-06 07:01:25 +01:00
|
|
|
name:
|
|
|
|
- pip
|
|
|
|
- setuptools
|
|
|
|
state: latest
|
2021-06-21 19:58:51 +02:00
|
|
|
virtualenv: /opt/borgmatic
|
|
|
|
virtualenv_command: "{{ python_bin }} -m venv"
|
2019-02-28 11:40:24 +01:00
|
|
|
|
2022-02-28 07:28:37 +01:00
|
|
|
- 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:
|
2020-02-17 17:21:21 +01:00
|
|
|
name: "{{ borg_python_packages }}"
|
2021-06-21 19:58:51 +02:00
|
|
|
virtualenv: /opt/borgmatic
|
2020-12-07 12:52:40 +01:00
|
|
|
when: borg_python_packages is defined
|
2018-10-06 14:04:20 +02:00
|
|
|
|
2021-06-21 19:58:51 +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
|
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
|
|
|
|
2019-09-23 18:30:22 +02:00
|
|
|
- name: Create new repository for server
|
|
|
|
borgbase:
|
|
|
|
repository_name: "{{ bb_repo_name }}"
|
2020-02-17 17:21:21 +01:00
|
|
|
token: "{{ bb_token }}"
|
2019-09-23 18:30:22 +02:00
|
|
|
new_ssh_key: "{{ bb_new_sshkey }}"
|
|
|
|
ssh_key: "{{ bb_sshkey }}"
|
|
|
|
append_only: "{{ bb_append }}"
|
|
|
|
quota_enable: "{{ bb_quota }}"
|
|
|
|
quota: "{{ bb_quota_size }}"
|
|
|
|
region: "{{ bb_region }}"
|
|
|
|
alertdays: "{{ bb_alertdays }}"
|
|
|
|
delegate_to: localhost
|
|
|
|
become: no
|
|
|
|
register: repo_creation
|
|
|
|
when: create_repo
|
2020-02-17 17:21:21 +01:00
|
|
|
|
2019-09-23 18:30:22 +02:00
|
|
|
- name: Set Repository Fact
|
|
|
|
set_fact:
|
2020-11-18 04:41:57 +01:00
|
|
|
borg_repository: |-
|
|
|
|
{% if borg_repository is defined and borg_repository is string %}
|
|
|
|
{{ [borg_repository] + [ repo_creation['data']['repoPath'] ] }}
|
|
|
|
{% elif borg_repository is defined %}
|
|
|
|
{{ borg_repository + [ repo_creation['data']['repoPath'] ] }}
|
|
|
|
{% else %}
|
|
|
|
{{ repo_creation['data']['repoPath'] }}
|
|
|
|
{% endif %}
|
2019-09-23 18:30:22 +02:00
|
|
|
when: create_repo
|
|
|
|
|
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)
|
|
|
|
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 }}"
|
2021-06-21 19:38:55 +02:00
|
|
|
job: "borgmatic -c /etc/borgmatic/{{ borgmatic_config_name }} --create --prune"
|
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 }}"
|
2021-06-21 19:38:55 +02:00
|
|
|
job: "borgmatic -c /etc/borgmatic/{{ borgmatic_config_name }} --check"
|
2019-05-01 04:39:07 +02:00
|
|
|
when: borgmatic_large_repo
|
|
|
|
|
|
|
|
- name: Add cron-job for borgmatic (normal-sized 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
|
2019-05-01 04:39:07 +02:00
|
|
|
when: not borgmatic_large_repo
|
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
|