Initial Ansible automation for hobbs.farm infrastructure
Complete IaC covering: - 14 roles: common, docker, traefik, vaultwarden, monitoring, media, matrix, home_assistant, frigate, adguard, gitea, semaphore, openclaw, security, backup - Inventory for all hosts (Peggy, Bart, Yoda, NAS, Firewalla) - Stack playbooks: core-infrastructure, monitoring, media, communication, automation, smarthome, security-hardening - Maintenance playbooks: update-containers, backup, health-check - Production Docker Compose templates with Traefik labels - Security hardening (sysctl, auditd, UFW, fail2ban) - Automated backups with retention policy
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
---
|
||||
backup_script_path: /usr/local/bin/homelab-backup.sh
|
||||
backup_schedule: "0 2 * * *"
|
||||
backup_retention_days: 30
|
||||
backup_sources:
|
||||
- /data/docker-compose
|
||||
backup_destination: /mnt/nas/backups/{{ inventory_hostname }}
|
||||
backup_pre_commands: []
|
||||
backup_post_commands: []
|
||||
@@ -0,0 +1,43 @@
|
||||
---
|
||||
- name: Ensure backup destination directory exists
|
||||
ansible.builtin.file:
|
||||
path: "{{ backup_destination }}"
|
||||
state: directory
|
||||
owner: glyptic
|
||||
group: glyptic
|
||||
mode: "0750"
|
||||
tags: [backup]
|
||||
|
||||
- name: Deploy backup script
|
||||
ansible.builtin.template:
|
||||
src: backup.sh.j2
|
||||
dest: "{{ backup_script_path }}"
|
||||
owner: root
|
||||
group: root
|
||||
mode: "0750"
|
||||
tags: [backup]
|
||||
|
||||
- name: Configure backup cron job
|
||||
ansible.builtin.cron:
|
||||
name: "homelab-backup"
|
||||
minute: "0"
|
||||
hour: "2"
|
||||
job: "{{ backup_script_path }} >> /var/log/homelab-backup.log 2>&1"
|
||||
user: root
|
||||
tags: [backup]
|
||||
|
||||
- name: Configure backup log rotation
|
||||
ansible.builtin.copy:
|
||||
content: |
|
||||
/var/log/homelab-backup.log {
|
||||
weekly
|
||||
rotate 4
|
||||
compress
|
||||
missingok
|
||||
notifempty
|
||||
}
|
||||
dest: /etc/logrotate.d/homelab-backup
|
||||
owner: root
|
||||
group: root
|
||||
mode: "0644"
|
||||
tags: [backup]
|
||||
@@ -0,0 +1,42 @@
|
||||
#!/bin/bash
|
||||
# Homelab Backup Script - Managed by Ansible
|
||||
# Host: {{ inventory_hostname }}
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
BACKUP_DIR="{{ backup_destination }}"
|
||||
DATE=$(date +%Y%m%d_%H%M%S)
|
||||
HOSTNAME="{{ inventory_hostname }}"
|
||||
BACKUP_FILE="${BACKUP_DIR}/${HOSTNAME}_${DATE}.tar.gz"
|
||||
RETENTION_DAYS="{{ backup_retention_days }}"
|
||||
|
||||
echo "=== Backup started at $(date) ==="
|
||||
echo "Destination: ${BACKUP_FILE}"
|
||||
|
||||
# Pre-backup commands
|
||||
{% for cmd in backup_pre_commands %}
|
||||
echo "Running pre-backup: {{ cmd }}"
|
||||
{{ cmd }}
|
||||
{% endfor %}
|
||||
|
||||
# Create backup
|
||||
tar czf "${BACKUP_FILE}" \
|
||||
{% for source in backup_sources %}
|
||||
{{ source }} \
|
||||
{% endfor %}
|
||||
2>/dev/null || true
|
||||
|
||||
BACKUP_SIZE=$(du -sh "${BACKUP_FILE}" | cut -f1)
|
||||
echo "Backup created: ${BACKUP_FILE} (${BACKUP_SIZE})"
|
||||
|
||||
# Post-backup commands
|
||||
{% for cmd in backup_post_commands %}
|
||||
echo "Running post-backup: {{ cmd }}"
|
||||
{{ cmd }}
|
||||
{% endfor %}
|
||||
|
||||
# Cleanup old backups
|
||||
echo "Removing backups older than ${RETENTION_DAYS} days..."
|
||||
find "${BACKUP_DIR}" -name "${HOSTNAME}_*.tar.gz" -mtime +${RETENTION_DAYS} -delete
|
||||
|
||||
echo "=== Backup completed at $(date) ==="
|
||||
Reference in New Issue
Block a user