Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| ce9b5d58b4 | |||
| 2c29ea2780 |
@@ -1,3 +1,5 @@
|
|||||||
# Ansible Collection
|
# Ansible Collection
|
||||||
|
|
||||||
Opinionated set of roles to configure reasonable defaults for newly provisioned Debian / Ubuntu VMs running Docker. The repository provides a ready-to-use Ansible Collection (`studio.ansible`) containing reusable roles.
|
Opinionated set of roles to configure reasonable defaults for newly provisioned Debian / Ubuntu VMs running Docker. The repository provides:
|
||||||
|
- An Ansible Collection (`studio.ansible`) containing reusable roles. Use with ansible-galaxy's `requirements.yml`.
|
||||||
|
- A ready-to-use playbook configured by passing CLI vars `--extra-vars "ansible_host=${HOST_IP}` e.g. through CI / CD.
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
[target]
|
||||||
|
target_host ansible_host="{{ ansible_host }}"
|
||||||
|
|
||||||
|
[all:vars]
|
||||||
|
ansible_user="{{ ansible_user }}"
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
---
|
||||||
|
- name: Setup machines
|
||||||
|
hosts: all
|
||||||
|
become: true
|
||||||
|
|
||||||
|
roles:
|
||||||
|
- base
|
||||||
|
- users
|
||||||
|
- security
|
||||||
|
- docker
|
||||||
|
# - backup
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
# ansible/roles/backup/defaults/main.yml
|
|
||||||
---
|
|
||||||
## Directories to include in the backup
|
|
||||||
backup_include_paths:
|
|
||||||
- /etc
|
|
||||||
- /opt/docker
|
|
||||||
|
|
||||||
## Directories to exclude from the backup
|
|
||||||
backup_exclude_paths: [] ## Nothing to exclude
|
|
||||||
|
|
||||||
## Restic retention policy
|
|
||||||
backup_retention_daily: 7
|
|
||||||
backup_retention_weekly: 4
|
|
||||||
backup_retention_monthly: 6
|
|
||||||
@@ -1,31 +0,0 @@
|
|||||||
---
|
|
||||||
- name: Install Restic
|
|
||||||
ansible.builtin.apt:
|
|
||||||
name: restic
|
|
||||||
state: present
|
|
||||||
become: true
|
|
||||||
|
|
||||||
- name: Deploy restic backup script
|
|
||||||
ansible.builtin.template:
|
|
||||||
src: restic-backup.sh.j2
|
|
||||||
dest: /usr/local/bin/restic-backup.sh
|
|
||||||
mode: "0700" # Only root can read/execute this because it contains secrets
|
|
||||||
|
|
||||||
- name: Deploy restic systemd service
|
|
||||||
ansible.builtin.template:
|
|
||||||
src: restic-backup.service.j2
|
|
||||||
dest: /etc/systemd/system/restic-backup.service
|
|
||||||
mode: "0644"
|
|
||||||
|
|
||||||
- name: Deploy restic systemd timer
|
|
||||||
ansible.builtin.template:
|
|
||||||
src: restic-backup.timer.j2
|
|
||||||
dest: /etc/systemd/system/restic-backup.timer
|
|
||||||
mode: "0644"
|
|
||||||
|
|
||||||
- name: Enable and start backup timer
|
|
||||||
ansible.builtin.systemd:
|
|
||||||
name: restic-backup.timer
|
|
||||||
enabled: yes
|
|
||||||
state: started
|
|
||||||
daemon_reload: yes
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
[Unit]
|
|
||||||
Description=Run Restic Backup
|
|
||||||
After=network-online.target
|
|
||||||
|
|
||||||
[Service]
|
|
||||||
Type=oneshot
|
|
||||||
ExecStart=/usr/local/bin/restic-backup.sh
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
## Ansible managed
|
|
||||||
|
|
||||||
## Secrets are passed via Ansible Vault variables
|
|
||||||
export RESTIC_REPOSITORY="{{ vault_restic_repo_url }}"
|
|
||||||
export RESTIC_PASSWORD="{{ vault_restic_password }}"
|
|
||||||
export AWS_ACCESS_KEY_ID="{{ vault_aws_access_key }}"
|
|
||||||
export AWS_SECRET_ACCESS_KEY="{{ vault_aws_secret_key }}"
|
|
||||||
|
|
||||||
set -e
|
|
||||||
|
|
||||||
echo "Starting Restic Backup at $(date)"
|
|
||||||
|
|
||||||
## Run the backup using paths and exclusions defined in group_vars
|
|
||||||
restic backup \
|
|
||||||
{% for path in backup_include_paths %}
|
|
||||||
"{{ path }}" \
|
|
||||||
{% endfor %}
|
|
||||||
{% for path in backup_exclude_paths %}
|
|
||||||
--exclude "{{ path }}" \
|
|
||||||
{% endfor %}
|
|
||||||
--cleanup-cache
|
|
||||||
|
|
||||||
restic forget \
|
|
||||||
--prune \
|
|
||||||
--keep-daily {{ backup_retention_daily }} \
|
|
||||||
--keep-weekly {{ backup_retention_weekly }} \
|
|
||||||
--keep-monthly {{ backup_retention_monthly }}
|
|
||||||
|
|
||||||
echo "Restic backup completed at $(date)"
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
[Unit]
|
|
||||||
Description=Run Restic Backup Daily at 4:00 AM
|
|
||||||
|
|
||||||
[Timer]
|
|
||||||
OnCalendar=*-*-* 04:00:00
|
|
||||||
Persistent=true
|
|
||||||
RandomizedDelaySec=1800
|
|
||||||
|
|
||||||
[Install]
|
|
||||||
WantedBy=timers.target
|
|
||||||
Reference in New Issue
Block a user