Add defaults and more tasks

This commit is contained in:
phil 2023-04-08 21:07:04 +02:00
parent 0c3f79c02c
commit ce5f7104f9
6 changed files with 276 additions and 24 deletions

24
tasks/borgbase.yml Normal file
View file

@ -0,0 +1,24 @@
---
- name: Read key from file
ansible.builtin.slurp:
src: "{{ borg_ssh_key_file_path }}/{{ borg_ssh_key_name }}.pub"
register: ssh_key
check_mode: true
- name: Add key to borgbase
adhawkins.borgbase.borgbase_ssh:
state: present
apikey: "{{ borgbase_api_key }}"
name: "{{ borgbase_ssh_key_name }}"
key: "{{ (ssh_key.content | b64decode).split()[:2] | join(' ') }}"
register: borgbase_key
- name: Create repo
adhawkins.borgbase.borgbase_repo:
state: present
apikey: "{{ borgbase_api_key }}"
name: "{{ ansible_hostname }}"
full_access_keys: ["{{ borgbase_key.key_id }}"]
quota_enabled: false
alert_days: 1
register: borgbase_repo

View file

@ -1,29 +1,29 @@
---
- name: Install Packages
ansible.builtin.import_tasks: packages.yml
tags: packages
- name: Generate an OpenSSH keypair
community.crypto.openssh_keypair:
path: "{{ backup_ssh_key_path }}"
path: "{{ borg_ssh_key_file_path }}"
type: "ed25519"
- name: Read key from file
ansible.builtin.slurp:
src: "{{ backup_ssh_key_path }}.pub"
register: ssh_key
check_mode: true
- name: Setup borgbase backup
ansible.builtin.import_tasks: borgbase.yml
when: borgbase is defined and borgbase
tags: borgbase
- name: Add key to borgbase
adhawkins.borgbase.borgbase_ssh:
state: present
apikey: "{{ borgbase_api_key }}"
name: "{{ borgbase_ssh_key_name }}"
key: "{{ (ssh_key.content | b64decode).split()[:2] | join(' ') }}"
register: borgbase_key
- name: Copy borgmatic configuration
ansible.builtin.template:
src: config.yaml.j2
dest: "/etc/borgmatic/{{ borgmatic_config_name }}"
mode: "0600"
- name: Create repo
adhawkins.borgbase.borgbase_repo:
state: present
apikey: "{{ borgbase_api_key }}"
name: "{{ ansible_hostname }}"
full_access_keys: ["{{ borgbase_key.key_id }}"]
quota_enabled: false
alert_days: 1
register: borgbase_repo
- name: Add single Cron job for borgmatic
ansible.builtin.cron:
name: "{{ borgmatic_timer_cron_name }}"
hour: "{{ borgmatic_timer_hour }}"
minute: "{{ borgmatic_timer_minute }}"
user: "{{ borg_user }}"
cron_file: "{{ borgmatic_timer_cron_name }}"
job: "borgmatic -c /etc/borgmatic/{{ borgmatic_config_name }}"

6
tasks/packages.yml Normal file
View file

@ -0,0 +1,6 @@
---
- name: "Packages | Install borgbackup and borgmatic"
ansible.builtin.apt:
pkg:
- borgbackup
- borgmatic