use more variables instead of hard-coding (fixes #3)

This commit is contained in:
Jannik Beyerstedt 2019-11-12 21:06:04 +01:00
parent d48064a7e3
commit 04686de59c
15 changed files with 101 additions and 70 deletions

View file

@ -1,8 +1,9 @@
---
# Server/Borgbackup: Install and Setup Borgbackup Backup Crobjob
# Variables (must be set!):
# - borgbackup_host
# - borgbackup_sub
# - borgbackup_passphrase
# - borgbackup_repo
# - borgbackup_hostname
- name: borgbackup - Install
include_tasks: "{{ item }}"
@ -22,8 +23,9 @@
group: "{{ ansible_user_id }}"
mode: 0775
when:
- borgbackup_host is defined
- borgbackup_sub is defined
- borgbackup_passphrase is defined
- borgbackup_repo is defined
- borgbackup_hostname is defined
- name: borgbackup - Run Borgbackup script at 1:00 daily
become: yes
cron:
@ -32,26 +34,24 @@
hour: "1"
job: "/usr/local/bin/borgbackup.sh"
when:
- borgbackup_host is defined
- borgbackup_sub is defined
- borgbackup_passphrase is defined
- borgbackup_repo is defined
- borgbackup_hostname is defined
# safeguard, if the host variables were removed
- name: borgbackup - Remove Borgbackup script if no borgbackup config
become: yes
file:
path: /usr/local/bin/borgbackup.sh
state: absent
when:
- borgbackup_host is not defined
- borgbackup_sub is not defined
- name: borgbackup - Remove Cronjob if no borgbackup config
become: yes
cron:
name: "Create Backup"
minute: "0"
hour: "1"
job: "/usr/local/bin/borgbackup.sh"
state: absent
when:
- borgbackup_host is not defined
- borgbackup_sub is not defined
- name: borgbackup - Uninstall
block:
- name: borgbackup - Remove Borgbackup script if no borgbackup config
become: yes
file:
path: /usr/local/bin/borgbackup.sh
state: absent
- name: borgbackup - Remove Cronjob if no borgbackup config
become: yes
cron:
name: "Create Backup"
minute: "0"
hour: "1"
job: "/usr/local/bin/borgbackup.sh"
state: absent
when: (borgbackup_passphrase is not defined) or (borgbackup_repo is not defined) or (borgbackup_hostname is not defined)