mirror of
https://github.com/borgbase/ansible-role-borgbackup.git
synced 2024-11-19 19:07:42 +01:00
87 lines
2.2 KiB
YAML
Executable File
87 lines
2.2 KiB
YAML
Executable File
---
|
|
- include_vars: '{{ ansible_pkg_mgr }}.yml'
|
|
- include: "{{ ansible_pkg_mgr }}.yml"
|
|
|
|
- name: Install required System Packages
|
|
package:
|
|
pkg: "{{ item }}"
|
|
state: installed
|
|
with_items: "{{ borg_packages }}"
|
|
|
|
- name: Update setuptools if needed
|
|
pip:
|
|
name: setuptools
|
|
state: latest
|
|
executable: "{{ pip_bin }}"
|
|
|
|
- name: Install required Python Packages
|
|
pip:
|
|
name: "{{ item }}"
|
|
executable: "{{ pip_bin }}"
|
|
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']
|
|
|
|
- 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)
|
|
block:
|
|
- cron:
|
|
name: "borgmatic"
|
|
hour: "{{ 6 |random }}"
|
|
minute: "{{ 59 |random }}"
|
|
user: "root"
|
|
cron_file: borgmatic
|
|
job: "/usr/local/bin/borgmatic -c /etc/borgmatic/{{ borgmatic_config_name }} --create --prune"
|
|
- cron:
|
|
name: "borgmatic-check"
|
|
day: "{{ 28 | random }}"
|
|
hour: "{{ range(7, 24) | random }}"
|
|
minute: "{{ 59 | random }}"
|
|
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)
|
|
block:
|
|
- cron:
|
|
name: "borgmatic"
|
|
hour: "{{ 6 | random }}"
|
|
minute: "{{ 59 | random }}"
|
|
user: "root"
|
|
cron_file: borgmatic
|
|
job: "/usr/local/bin/borgmatic -c /etc/borgmatic/{{ borgmatic_config_name }}"
|
|
- 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
|