2018-10-06 14:04:20 +02:00
|
|
|
---
|
2019-05-27 12:12:13 +02:00
|
|
|
- include_vars: '{{ ansible_pkg_mgr }}.yml'
|
|
|
|
- include: "{{ ansible_pkg_mgr }}.yml"
|
2018-10-06 14:04:20 +02:00
|
|
|
|
|
|
|
- name: Install required System Packages
|
2019-10-24 07:05:19 +02:00
|
|
|
package:
|
2018-10-06 14:04:20 +02:00
|
|
|
pkg: "{{ item }}"
|
2019-09-23 18:30:22 +02:00
|
|
|
state: present
|
2019-05-27 12:12:13 +02:00
|
|
|
with_items: "{{ borg_packages }}"
|
2018-10-06 14:04:20 +02:00
|
|
|
|
2019-02-28 11:40:24 +01:00
|
|
|
- name: Update setuptools if needed
|
2019-10-24 07:05:19 +02:00
|
|
|
pip:
|
2019-02-28 11:40:24 +01:00
|
|
|
name: setuptools
|
|
|
|
state: latest
|
2019-05-27 12:12:13 +02:00
|
|
|
executable: "{{ pip_bin }}"
|
2019-02-28 11:40:24 +01:00
|
|
|
|
2018-10-06 14:04:20 +02:00
|
|
|
- name: Install required Python Packages
|
|
|
|
pip:
|
|
|
|
name: "{{ item }}"
|
2019-05-27 12:12:13 +02:00
|
|
|
executable: "{{ pip_bin }}"
|
2018-10-06 14:04:20 +02:00
|
|
|
with_items: "{{ borg_python_packages }}"
|
|
|
|
|
|
|
|
- name: Ensure root has SSH key.
|
|
|
|
user:
|
|
|
|
name: "root"
|
|
|
|
generate_ssh_key: yes
|
|
|
|
ssh_key_file: .ssh/id_ed25519
|
|
|
|
ssh_key_type: ed25519
|
|
|
|
register: root_user
|
|
|
|
|
|
|
|
- debug:
|
|
|
|
var: root_user['ssh_public_key']
|
2019-10-24 07:05:19 +02:00
|
|
|
|
2019-09-23 18:30:22 +02:00
|
|
|
- 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: "{{ repo_creation['data']['repoPath'] }}"
|
|
|
|
when: create_repo
|
|
|
|
|
2019-10-24 07:05:19 +02:00
|
|
|
- name: Ensures /etc/borgmatic.d exists
|
2018-10-06 14:04:20 +02:00
|
|
|
file:
|
2019-10-24 07:05:19 +02:00
|
|
|
path: /etc/borgmatic.d
|
2018-10-06 14:04:20 +02:00
|
|
|
state: directory
|
|
|
|
mode: 0700
|
|
|
|
owner: root
|
|
|
|
|
|
|
|
- name: Add Borgmatic Configuration
|
|
|
|
template:
|
|
|
|
src: config.yaml.j2
|
2019-10-24 07:05:19 +02:00
|
|
|
dest: "/etc/borgmatic.d/{{ item | regex_replace('\\/$', '') | basename }}.yaml"
|
2018-10-06 14:04:20 +02:00
|
|
|
mode: 0600
|
2019-10-24 07:05:19 +02:00
|
|
|
with_items: "{{ borg_source_directories }}"
|
|
|
|
|
|
|
|
- debug: msg="/etc/borgmatic.d/{{ item | regex_replace('\\/$', '') | basename }}.yaml"
|
|
|
|
with_items: "{{ borg_source_directories }}"
|
2018-10-06 14:04:20 +02:00
|
|
|
|
2019-05-15 06:44:10 +02:00
|
|
|
- name: Add cron-job for borgmatic (large repo, create and check separate)
|
|
|
|
block:
|
2019-10-24 07:05:19 +02:00
|
|
|
- cron:
|
2019-05-15 06:44:10 +02:00
|
|
|
name: "borgmatic"
|
|
|
|
hour: "{{ 6 |random }}"
|
|
|
|
minute: "{{ 59 |random }}"
|
|
|
|
user: "root"
|
|
|
|
cron_file: borgmatic
|
2019-10-24 07:05:19 +02:00
|
|
|
job: "/usr/local/bin/borgmatic --create --prune"
|
|
|
|
- cron:
|
2019-05-15 06:44:10 +02:00
|
|
|
name: "borgmatic-check"
|
|
|
|
day: "{{ 28 | random }}"
|
|
|
|
hour: "{{ range(7, 24) | random }}"
|
|
|
|
minute: "{{ 59 | random }}"
|
|
|
|
user: "root"
|
|
|
|
cron_file: borgmatic
|
2019-10-24 07:05:19 +02:00
|
|
|
job: "/usr/local/bin/borgmatic --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:
|
2019-10-24 07:05:19 +02:00
|
|
|
- cron:
|
2019-05-15 06:44:10 +02:00
|
|
|
name: "borgmatic"
|
|
|
|
hour: "{{ 6 | random }}"
|
|
|
|
minute: "{{ 59 | random }}"
|
|
|
|
user: "root"
|
|
|
|
cron_file: borgmatic
|
2019-10-24 07:05:19 +02:00
|
|
|
job: "/usr/local/bin/borgmatic"
|
2019-05-15 06:44:10 +02:00
|
|
|
- cron:
|
|
|
|
name: "borgmatic-check"
|
|
|
|
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"
|
|
|
|
cron_file: borgmatic
|
|
|
|
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
|