This repo is destined for my server automations and setup.
Comprehensive Ansible playbooks for server provisioning and configuration management.
This repository is designed for public sharing while keeping your actual server details private.
inventory/local.yml).vault_password)group_vars/vault.yml)host_vars/*.yml)pip install -r requirements-python.txt./setup-inventory.shinventory/local.ymlansible-vault edit group_vars/vault.ymlansible all -m pingSee inventory/README.md for detailed instructions.
system.yml â System baseline, Docker, and security hardening.
Target: dynamic (-e target_host=<host>)
ansible-playbook system.yml -e target_host=runner
user.yml â User creation, SSH keys, and dotfiles.
Target: dynamic (-e target_host=<host>)
ansible-playbook user.yml -e target_host=runner
generic_setup.yml â Combined system + user setup (one-shot provisioning).
Target: dynamic (-e target_host=<host>)
ansible-playbook generic_setup.yml -e target_host=runner
runner.yml â Dev/media services (Frigate, Immich, Forgejo, LLM stack, ...). Two-phase: configures NAS exports on storage first, then deploys to runner.
ansible-playbook runner.yml
ansible-playbook runner.yml --tags frigate
storage.yml â Media automation (Jellyfin, Arr stack, Calibre, restic server).
ansible-playbook storage.yml
ansible-playbook storage.yml --tags jellyfin
connectivity.yml â VPN, DNS, and reverse proxy.
ansible-playbook connectivity.yml
homeassistant.yml â Home Assistant Supervised installation.
ansible-playbook homeassistant.yml
entrance.yml â Zigbee, Thread, and energy monitoring gateway.
ansible-playbook entrance.yml
doorbell.yml â IoT camera doorbell.
ansible-playbook doorbell.yml
hifi-nodes.yml â Multi-room audio clients on HiFi nodes (Snapcast or Sendspin).
ansible-playbook hifi-nodes.yml
ansible-playbook hifi-nodes.yml -e audio_client_type=sendspin
backup.yml â Backup and restore Docker services via restic.
ansible-playbook backup.yml # all services
ansible-playbook backup.yml -e "backup_services=immich,frigate" # specific services
ansible-playbook backup.yml -e "backup_mode=restore backup_services=immich" # restore
ansible-playbook backup.yml --tags discovery # dry-run discovery
update-services.yml â Pull latest container images and restart.
ansible-playbook update-services.yml # all hosts
ansible-playbook update-services.yml --tags jellyfin # specific service
server_automation/
ansible.cfg # Ansible configuration
requirements.yml # Galaxy role dependencies
provision.yml # Main provisioning playbook
prod.yml # Production environment
staging.yml # Staging environment
dev.yml # Development environment
role-*.yml # Role-specific playbooks
security-*.yml # Security playbooks
inventory/
hosts # Main inventory
production # Production hosts
staging # Staging hosts
development # Development hosts
group_vars/ # Group variables
host_vars/ # Host-specific variables
group_vars/
all.yml # Global variables
prod.yml # Production variables
staging.yml # Staging variables
dev.yml # Development variables
security.yml # Security variables
host_vars/
example-server.yml # Host template
roles/
user/ # User management
system/ # System configuration
backup/ # Backup system
gui-gnome/ # GNOME desktop
audio-client/ # Multi-room audio (Snapcast/Sendspin)
security-baseline/ # Security hardening
firewall/ # Firewall configuration
The services/ directory contains service-specific deployment roles:
services/
web/ # Web services (Nginx, Apache)
api/ # API services (Node.js, Python)
database/ # Database services (PostgreSQL, Redis)
monitoring/ # Monitoring stack (Prometheus, Grafana)
cache/ # Caching services (Redis, Memcached)
templates/ # Service templates and examples
service-template/ # Template for creating new services
.gitea/workflows/
ci.yml # Validation workflow (lint, test, security)
deploy.yml # Deployment workflow (staging, production)
This repository integrates two key geerlingguy roles:
See ROLES-INTEGRATION.md for detailed configuration and usage.
# 1. Install Ansible Galaxy roles
ansible-galaxy install -r requirements.yml
# 2. Install collections
ansible-galaxy collection install -r collections.yml
# 3. Set up secure inventory (first time only)
./setup-inventory.sh
# 4. Configure your servers and secrets
nano inventory/local.yml
ansible-vault edit group_vars/vault.yml
Full provisioning:
ansible-playbook provision.yml
Environment-specific (if using multiple inventories):
ansible-playbook prod.yml -i inventory/production.yml
ansible-playbook staging.yml -i inventory/staging.yml
ansible-playbook dev.yml
Role-specific:
ansible-playbook role-system.yml
ansible-playbook role-docker.yml
Security hardening:
ansible-playbook security-baseline.yml -e "security_level=high"
ansible-playbook firewall.yml
Playbooks support granular execution using tags:
# Run only system tasks
ansible-playbook provision.yml --tags system
# Run everything except GUI
ansible-playbook provision.yml --skip-tags gui
# Run multiple tags
ansible-playbook provision.yml --tags system,user,docker
Available tags: system, user, backup, gui, audio, docker, security, firewall, wifi
env: Environment type (prod, staging, dev)security_level: Security strictness (low, medium, high)Each role has its own defaults in roles/<role>/defaults/main.yml
host_vars/)group_vars/)any_errors_fatalThis repository includes comprehensive Ansible Vault integration for secure secrets management:
vault/
envs/ # Environment-specific secrets
dev/
staging/
prod/
secrets/ # Categorized secrets
api_keys/
certificates/
databases/
ssh_keys/
cloud_credentials/
passwords/ # Vault password management
scripts/ # Helper scripts
templates/ # Template files
Generate vault passwords:
./vault/scripts/generate-vault-passwords.sh
Encrypt vault files:
./vault/scripts/encrypt-vault.sh dev
./vault/scripts/encrypt-vault.sh staging
./vault/scripts/encrypt-vault.sh prod
Use in playbooks:
ANSIBLE_ENV=dev ansible-playbook playbook.yml --vault-password-file=./vault/passwords/.vault-pass.envs
See vault/README.md for complete documentation.
The inventory system supports multiple environments and dynamic cloud integration:
See inventory/README.md for detailed usage.
# Validate playbook syntax
ansible-playbook --syntax-check provision.yml
# Validate inventory
ansible-inventory -i inventory/hosts --list
# Test vault integration
./vault/scripts/test-vault-integration.sh dev
# Test role integration
./validate-integration.sh
# Check what would change
ansible-playbook provision.yml --check --diff
This repository includes a comprehensive CI/CD pipeline using Forgejo/Gitea Actions with separate validation and deployment workflows.
Code Push â CI Validation â Merge to Main â Automatic Deployment
â â â â
Feature Syntax Check Staging Deploy Production Deploy
Branch Security Scan Health Checks Manual Approval
Integration Rollback Ready Full Monitoring
.gitea/workflows/ci.yml)Triggers: Push to main/develop, Pull Requests Purpose: Comprehensive validation without deployment
Jobs:
.gitea/workflows/deploy.yml)Triggers: Push to main (after CI success), Manual workflow dispatch Purpose: Service deployment with rollback capability
Jobs:
deploy.yml)Separate from site.yml, focuses exclusively on service deployment:
# Deploy all services to staging
ansible-playbook -i inventory/staging deploy.yml
# Deploy specific services
ansible-playbook -i inventory/production deploy.yml \
--extra-vars "target_services=web,api"
# Rollback deployment
ansible-playbook -i inventory/production deploy.yml \
--tags rollback --extra-vars "rollback_version=v1.2.3"
Create Service Role:
cp -r services/templates/service-template services/your-service
# Edit and customize the service configuration
Update Deploy Configuration:
# In group_vars/all.yml or environment-specific files
your_service_services:
- name: your-service-app
image: your-org/your-service
tag: "v1.0.0"
ports: ["8080:8080"]
environment:
ENV: "production"
Add Health Checks:
your_service_health_checks:
- name: your-service-app
port: 8080
path: "/health"
expected_status: 200
The deployment workflow requires self-hosted runners for:
# Install Forgejo Runner
sudo apt update
sudo apt install docker.io ansible python3-pip
pip3 install docker
# Configure runner with repository
./setup-runner.sh --token YOUR_RUNNER_TOKEN
Required secrets in Forgejo/Gitea repository settings:
SSH_PRIVATE_KEY: SSH key for server accessSTAGING_HOST: Staging server hostname/IPPRODUCTION_HOST: Production server hostname/IPVAULT_PASSWORD: Ansible Vault password for secretsAll deployments include comprehensive health monitoring:
# Automatic rollback (triggered on deployment failure)
ansible-playbook -i inventory/production deploy.yml --tags rollback
# Manual rollback to specific version
ansible-playbook -i inventory/production deploy.yml \
--tags rollback --extra-vars "rollback_version=20231201-123456"
/var/log/deployments/deployment.log# Test the same checks that run in CI
./test-ci-locally.sh
# Run specific validation
./validate-integration.sh
# Test deployment playbook
ansible-playbook deploy.yml --check --diff -i inventory/staging
# Test new service locally
docker-compose -f services/your-service/docker-compose.yml up -d
# Test service health
curl -f http://localhost:8080/health
# Test with Ansible
ansible-playbook deploy.yml --tags your-service --check
The backup system uses restic with a REST server on storage.home. It auto-discovers all Docker Compose services under /docker/ on every host in the docker_servers inventory group.
# See what services exist on which hosts
ansible-playbook backup.yml --tags discovery
# Backup ALL services on ALL hosts
ansible-playbook backup.yml
# Backup a single service (runs only on the host that has it)
ansible-playbook backup.yml -e "backup_services=immich"
# Backup multiple specific services
ansible-playbook backup.yml -e "backup_services=immich,frigate,forgejo"
# Backup with verbose restic output
ansible-playbook backup.yml -e "backup_services=jellyfin" -v
# Restore a single service from its latest snapshot
ansible-playbook backup.yml -e "backup_mode=restore backup_services=immich"
# Restore multiple services
ansible-playbook backup.yml -e "backup_mode=restore backup_services=immich,frigate"
# List all snapshots
restic snapshots
# List snapshots for a specific service
restic snapshots --tag immich
# Check repository integrity
restic check
# Manual prune
restic forget --keep-last 10 --prune
Restic environment variables (RESTIC_REPOSITORY, RESTIC_PASSWORD) must be set or passed for CLI usage. The backup password is stored in the Ansible vault as restic_backup_password.
ansible-galaxy install -r requirements.yml.gitea/workflows/README.md for troubleshooting# Enable verbose output
ansible-playbook provision.yml -vvv
# Debug specific tasks
ansible-playbook provision.yml --tags system -vvv
# Debug deployment issues
ansible-playbook deploy.yml --check --diff --tags health-check
# Check CI status
git status && git log --oneline -5
# Test CI locally
./test-ci-locally.sh
# Debug deployment
ansible-playbook deploy.yml --check --diff -vvv
# View deployment logs
tail -f /var/log/deployments/deployment.log
For issues and questions:
This project is licensed under the MIT License - see the LICENSE file for details.