e29c4df98c
Remove Fedora 31 as it's EOL and use the borgbackup, borgmatic and cython packages from Fedora's repositories.
132 lines
3.8 KiB
YAML
Executable File
132 lines
3.8 KiB
YAML
Executable File
---
|
|
- 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"
|
|
|
|
- name: Run OS-specific setup
|
|
include: "{{ item }}"
|
|
with_first_found:
|
|
- "{{ ansible_os_family }}-{{ ansible_distribution_major_version }}.yml"
|
|
- "{{ ansible_os_family }}.yml"
|
|
|
|
- name: Install required System Packages
|
|
package:
|
|
name: "{{ borg_packages }}"
|
|
state: present
|
|
|
|
- name: Update setuptools if needed
|
|
tags: skip_ansible_lint
|
|
pip:
|
|
name: setuptools
|
|
state: latest
|
|
executable: "{{ pip_bin }}"
|
|
|
|
- name: Install required Python Packages
|
|
pip:
|
|
name: "{{ borg_python_packages }}"
|
|
executable: "{{ pip_bin }}"
|
|
when: borg_python_packages is defined
|
|
|
|
- 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
|
|
|
|
- debug:
|
|
var: root_user['ssh_public_key']
|
|
|
|
- name: Create new repository for server
|
|
borgbase:
|
|
repository_name: "{{ bb_repo_name }}"
|
|
token: "{{ bb_token }}"
|
|
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
|
|
|
|
- name: Set Repository Fact
|
|
set_fact:
|
|
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 %}
|
|
when: create_repo
|
|
|
|
- name: Ensures /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)
|
|
tags: molecule-idempotence-notest
|
|
block:
|
|
- name: Add cron job for regular create and prune
|
|
cron:
|
|
name: "borgmatic"
|
|
hour: "{{ borgmatic_cron_hour }}"
|
|
minute: "{{ borgmatic_cron_minute }}"
|
|
user: "root"
|
|
cron_file: borgmatic
|
|
job: "/usr/local/bin/borgmatic -c /etc/borgmatic/{{ borgmatic_config_name }} --create --prune"
|
|
- name: Add cron job for infrequent checks
|
|
cron:
|
|
name: "borgmatic-check"
|
|
day: "{{ borgmatic_cron_checks_day }}"
|
|
hour: "{{ borgmatic_cron_checks_hour }}"
|
|
minute: "{{ borgmatic_cron_checks_minute }}"
|
|
user: "root"
|
|
cron_file: borgmatic
|
|
job: "/usr/local/bin/borgmatic -c /etc/borgmatic/{{ borgmatic_config_name }} --check"
|
|
when: borgmatic_large_repo
|
|
|
|
- name: Add cron-job for borgmatic (normal-sized repo)
|
|
tags: molecule-idempotence-notest
|
|
block:
|
|
- name: Add cron job for create, check and prune
|
|
cron:
|
|
name: "borgmatic"
|
|
hour: "{{ borgmatic_cron_hour }}"
|
|
minute: "{{ borgmatic_cron_minute }}"
|
|
user: "root"
|
|
cron_file: borgmatic
|
|
job: "/usr/local/bin/borgmatic"
|
|
- name: Ensure separate check cron job is absent
|
|
cron:
|
|
name: "borgmatic-check"
|
|
state: absent
|
|
when: not borgmatic_large_repo
|
|
|
|
- name: Set PATH for borgmatic cron job.
|
|
cron:
|
|
user: "root"
|
|
cron_file: borgmatic
|
|
name: PATH
|
|
env: yes
|
|
value: /usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
|