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 - Debian Stretch Version
# Variables (must be set!):
# - borgbackup_host
# - borgbackup_sub
# - borgbackup_passphrase
# - borgbackup_repo
# - borgbackup_hostname
# For Debian Stretch, use a newer package version from backports
@ -30,6 +31,7 @@
update_cache: yes
cache_valid_time: 3600
when:
- borgbackup_host is defined
- borgbackup_sub is defined
- borgbackup_passphrase is defined
- borgbackup_repo is defined
- borgbackup_hostname is defined
- ansible_distribution_release == 'stretch'

View file

@ -1,8 +1,9 @@
---
# Server/Borgbackup: Install and Setup Borgbackup Backup Crobjob - Default Debian Version
# Variables (must be set!):
# - borgbackup_host
# - borgbackup_sub
# - borgbackup_passhrase
# - borgbackup_repo
# - borgbackup_hostname
# For all other Debian versions, simply install borgbackup
@ -12,6 +13,7 @@
name: borgbackup
state: present
when:
- borgbackup_host is defined
- borgbackup_sub is defined
- borgbackup_passphrase is defined
- borgbackup_repo is defined
- borgbackup_hostname is defined
- ansible_distribution_release != 'stretch'

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)

View file

@ -30,8 +30,8 @@
mode: 0555
- name: caddyserver - Copy Caddy systemd service file
become: yes
copy:
src: "{{ role_path }}/files/caddy.service"
template:
src: "{{ role_path }}/templates/caddy.service"
dest: /etc/systemd/system/caddy.service
owner: root
group: root

View file

@ -7,3 +7,4 @@
- name: caddyserver - Setup caddy server
include_tasks: "caddy-setup.yml"
when: caddy_email is defined

View file

@ -46,4 +46,4 @@
cron:
name: MAILTO
env: yes
value: "device-{{ ansible_hostname }}@jtbx.de"
value: "{{ cron_email }}"

View file

@ -7,18 +7,18 @@
name: curl
state: present
- name: dyndns - Copy hosts.jtbx.de dynDNS script
- name: dyndns - Copy dynDNS script
become: yes
copy:
src: "{{ role_path }}/files/ddns-hosts.sh"
template:
src: "{{ role_path }}/templates/ddns-hosts.sh"
dest: /usr/local/bin/ddns-hosts.sh
owner: "{{ ansible_user_id }}"
group: "{{ ansible_user_id }}"
mode: 0775
- name: dyndns - Create cronjob for hosts.jtbx.de dynDNS script
- name: "dyndns - Create cronjob for {{ ddns_domain }} dynDNS script"
become: yes
cron:
name: "hosts.jtbx.de dynDNS"
name: "{{ ddns_domain }} dynDNS"
minute: "*/5"
hour: "*"
job: "/usr/local/bin/ddns-hosts.sh > /dev/null"

View file

@ -1,7 +1,7 @@
---
# Server/Telegraf: Install and Setup Telegraf Monitoring
# Variables:
# - telegraf_snmp_fra80: boolean, enable SNMP monitoring for the fra80 network
# - telegraf_snmp: boolean, enable SNMP monitoring for the fra80 network
# - telegraf_docker: boolean, enable docker monitoring
- name: telegraf - Install apt-transport-https