From da07ed37ebc4195bc4a54daea837e818811e7cf3 Mon Sep 17 00:00:00 2001 From: Radar231 Date: Thu, 6 Jul 2023 18:57:48 -0400 Subject: [PATCH] initial check-in --- README.md | 6 +++ meta/main.yml | 9 +++++ tasks/main.yml | 100 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 115 insertions(+) create mode 100644 README.md create mode 100644 meta/main.yml create mode 100644 tasks/main.yml diff --git a/README.md b/README.md new file mode 100644 index 0000000..4a74d7c --- /dev/null +++ b/README.md @@ -0,0 +1,6 @@ +# Ansible Role: borg_backups + +## Introduction + +This role will install borgbackup and the borg backup scripts on the target host. + diff --git a/meta/main.yml b/meta/main.yml new file mode 100644 index 0000000..eb37897 --- /dev/null +++ b/meta/main.yml @@ -0,0 +1,9 @@ +galaxy_info: + author: radar231 + + license: license (GPL-2.0-or-later, MIT, etc) + min_ansible_version: 2.1 + galaxy_tags: [] +dependencies: [] + +# EOF diff --git a/tasks/main.yml b/tasks/main.yml new file mode 100644 index 0000000..599fa22 --- /dev/null +++ b/tasks/main.yml @@ -0,0 +1,100 @@ +--- +########################################################################### +# +# This role will set up our borg backup configuration. +# +########################################################################### +# tasks file for borg_backups + +- debug: msg="Setting up borg backups (borg-bu)" + +############################################################ +- name: Make sure borgbackup package is installed (Debian) + apt: + name: borgbackup + state: latest + when: ansible_os_family == "Debian" + +############################################################ +- name: Make sure borgbackup package is installed (Arch) + pacman: + name: borgbackup + state: latest + when: ansible_os_family == "Archlinux" + +############################################################ +- name: Create /usr/local/log directory + file: + path: "/usr/local/log" + state: directory + owner: "root" + group: "root" + mode: "0755" + +############################################################ +- name: checkout borg_backups repository + ansible.builtin.git: + repo: 'http://git.radar231.com/radar231/borg_backups' + dest: "/tmp/{{ ansible_hostname }}/borg_backups" + delegate_to: 127.0.0.1 + +############################################################ +- name: Copy files to /usr/local/bin + copy: + src: "/tmp/{{ ansible_hostname }}/borg_backups/{{ item }}" + dest: "/usr/local/bin/{{ item }}" + owner: "root" + group: "root" + mode: "0755" + loop: + - borg-bu + - borg-check + +############################################################ +- name: Copy bu-list to /usr/local/etc (if it doesn't exist) + copy: + src: "/tmp/{{ ansible_hostname }}/du_backups/bu-list" + dest: "/usr/local/etc/bu-list" + owner: "root" + group: "root" + mode: "0644" + force: false + +############################################################ +- name: Add backup entry to root crontab + cron: + name: "Daily backup" + minute: "00" + hour: "01" + job: "/usr/local/bin/borg-bu >>/usr/local/log/borg_cron_run.log 2>&1 &" + +############################################################ +- name: Generate ssh keys for root user (if they dont already exist) + openssh_keypair: + path: "/root/.ssh/id_rsa" + comment: "root@{{ ansible_hostname }}" + owner: "root" + group: "root" + force: false + regenerate: never + +############################################################ +- name: Display root public ssh key + command: "cat /root/.ssh/id_rsa.pub" + register: command_output + +############################################################ +- name: Print message and ssh key + debug: + msg: + - "Copy the following public ssh key to the borg authorized_keys file on the backup server host:" + - "" + - "{{ command_output.stdout }}" + - "" + +############################################################ +- name: clean up cloned git repo + command: 'rm -rf /tmp/{{ ansible_hostname }}/borg_backups' + delegate_to: 127.0.0.1 + +# EOF