From dfc762b0058cf4a9ef7337c7a0883e2c5a5c3c9d Mon Sep 17 00:00:00 2001 From: Julien Dessaux Date: Mon, 15 Jul 2019 20:40:00 +0200 Subject: Ansible best practices and committed forgotten handlers for borg role --- files/borg.fact | 4 ++++ handlers/main.yml | 6 ++++++ templates/backup.sh.j2 | 12 ++++++++++-- vars/Alpine.yml | 2 +- vars/Gentoo.yml | 2 +- vars/OpenBSD.yml | 2 +- 6 files changed, 23 insertions(+), 5 deletions(-) create mode 100644 handlers/main.yml diff --git a/files/borg.fact b/files/borg.fact index 555143d..ee6504c 100644 --- a/files/borg.fact +++ b/files/borg.fact @@ -1,4 +1,8 @@ #!/bin/sh +############################################################################### +# \_o< WARNING : This file is being managed by ansible! >o_/ # +# ~~~~ ~~~~ # +############################################################################### echo '{' if [ -e '/root/.ssh/borg.pub' ]; then diff --git a/handlers/main.yml b/handlers/main.yml new file mode 100644 index 0000000..fed8e07 --- /dev/null +++ b/handlers/main.yml @@ -0,0 +1,6 @@ +--- +- name: reload openbsd cron + service: + name: cron + state: reloaded +... diff --git a/templates/backup.sh.j2 b/templates/backup.sh.j2 index a029080..6549fe2 100644 --- a/templates/backup.sh.j2 +++ b/templates/backup.sh.j2 @@ -1,11 +1,19 @@ #!/bin/sh +############################################################################### +# \_o< WARNING : This file is being managed by ansible! >o_/ # +# ~~~~ ~~~~ # +############################################################################### + +HOME=/root +PATH=${PATH}:/usr/local/bin +BORG_RSH="ssh -i /root/.ssh/borg" {% for job in borg_jobs %} {% if job.command_to_pipe is defined %} {{ job.command_to_pipe }} | BORG_RSH="ssh -i /root/.ssh/borg" borg create borg@{{ borg_server }}:/srv/borg/repos/{{ ansible_hostname }}::{{ job.name }}-{now} {{ job.path | default('-') }} {% else %} -BORG_RSH="ssh -i /root/.ssh/borg" borg create borg@{{ borg_server }}:/srv/borg/repos/{{ ansible_hostname }}::{{ job.name }}-{now} {{ job.path }} +borg create borg@{{ borg_server }}:/srv/borg/repos/{{ ansible_hostname }}::{{ job.name }}-{now} {{ job.path }} {% endif %} {% endfor %} -BORG_RSH="ssh -i /root/.ssh/borg" borg prune borg@{{ borg_server }}:/srv/borg/repos/{{ ansible_hostname }} {{ borg_prune_arguments }} +borg prune borg@{{ borg_server }}:/srv/borg/repos/{{ ansible_hostname }} {{ borg_prune_arguments }} diff --git a/vars/Alpine.yml b/vars/Alpine.yml index ff545b1..83a9fbe 100644 --- a/vars/Alpine.yml +++ b/vars/Alpine.yml @@ -1,4 +1,4 @@ --- borg_packages: - - 'borgbackup' + - borgbackup ... diff --git a/vars/Gentoo.yml b/vars/Gentoo.yml index a9eb31c..3f81849 100644 --- a/vars/Gentoo.yml +++ b/vars/Gentoo.yml @@ -1,4 +1,4 @@ --- borg_packages: - - 'app-backup/borgbackup' + - app-backup/borgbackup ... diff --git a/vars/OpenBSD.yml b/vars/OpenBSD.yml index ff545b1..83a9fbe 100644 --- a/vars/OpenBSD.yml +++ b/vars/OpenBSD.yml @@ -1,4 +1,4 @@ --- borg_packages: - - 'borgbackup' + - borgbackup ... -- cgit v1.2.3