initial check-in

This commit is contained in:
Radar231 2023-07-06 18:57:48 -04:00
commit da07ed37eb
3 changed files with 115 additions and 0 deletions

6
README.md Normal file
View File

@ -0,0 +1,6 @@
# Ansible Role: borg_backups
## Introduction
This role will install borgbackup and the borg backup scripts on the target host.

9
meta/main.yml Normal file
View File

@ -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

100
tasks/main.yml Normal file
View File

@ -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