Post-Tyranny-Tech-Infrastru.../ansible/roles/nextcloud/tasks/mount-volume.yml

75 lines
1.8 KiB
YAML
Raw Permalink Normal View History

feat: Use Hetzner Volumes for Nextcloud data storage (issue #18) Implement persistent block storage for Nextcloud user data, separating application and data layers: OpenTofu Changes: - tofu/volumes.tf: Create and attach Hetzner Volumes per client - Configurable size per client (default 100 GB for dev) - ext4 formatted, attached but not auto-mounted - tofu/variables.tf: Add nextcloud_volume_size to client config - tofu/terraform.tfvars: Set volume size for dev client (100 GB ~€5.40/mo) Ansible Changes: - ansible/roles/nextcloud/tasks/mount-volume.yml: New mount tasks - Detect volume device automatically - Format if needed, mount at /mnt/nextcloud-data - Add to fstab for persistence - Set correct permissions for www-data - ansible/roles/nextcloud/tasks/main.yml: Include volume mounting - ansible/roles/nextcloud/templates/docker-compose.nextcloud.yml.j2: - Use host mount /mnt/nextcloud-data/data instead of Docker volume - Keep app code in Docker volume (nextcloud-app) - User data now on Hetzner Volume Scripts: - scripts/resize-client-volume.sh: Online volume resizing - Resize via Hetzner API - Expand filesystem automatically - Show cost impact - Verify new size Documentation: - docs/storage-architecture.md: Complete storage guide - Architecture diagrams - Volume specifications - Sizing guidelines - Operations procedures - Performance considerations - Troubleshooting guide - docs/volume-migration.md: Step-by-step migration - Safe migration from Docker volumes - Rollback procedures - Verification checklist - Timeline estimates Benefits: ✅ Data independent from server instance ✅ Resize storage without rebuilding server ✅ Easy data migration between servers ✅ Better separation of concerns (app vs data) ✅ Simplified backup strategy ✅ Cost-optimized (pay for what you use) Volume Pricing: - 50 GB: ~€2.70/month - 100 GB: ~€5.40/month - 250 GB: ~€13.50/month - Resizable online, no downtime Note: Existing clients require manual migration Follow docs/volume-migration.md for safe migration procedure Closes #18 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
2026-01-17 21:07:48 +01:00
---
# Mount Hetzner Volume for Nextcloud Data Storage
#
# This task file handles mounting the Hetzner Volume that stores Nextcloud user data.
# The volume is created and attached by OpenTofu, we just mount it here.
- name: Wait for volume device to appear
wait_for:
path: /dev/disk/by-id/
timeout: 30
register: disk_ready
- name: Find Nextcloud volume device
shell: |
🚀 GREEN CLIENT DEPLOYMENT + CRITICAL SECURITY FIXES ═══════════════════════════════════════════════════════════════ ✅ COMPLETED: Green Client Deployment (green.vrije.cloud) ═══════════════════════════════════════════════════════════════ Services deployed and operational: - Traefik (reverse proxy with SSL) - Authentik SSO (auth.green.vrije.cloud) - Nextcloud (nextcloud.green.vrije.cloud) - Collabora Office (online document editing) - PostgreSQL databases (Authentik + Nextcloud) - Redis (caching + file locking) ═══════════════════════════════════════════════════════════════ 🔐 CRITICAL SECURITY FIX: Unique Passwords Per Client ═══════════════════════════════════════════════════════════════ PROBLEM FIXED: All clients were using IDENTICAL passwords from template (critical vulnerability). If one server compromised, all servers compromised. SOLUTION IMPLEMENTED: ✅ Auto-generate unique passwords per client ✅ Store securely in SOPS-encrypted files ✅ Easy retrieval with get-passwords.sh script NEW SCRIPTS: - scripts/generate-passwords.sh - Auto-generate unique 43-char passwords - scripts/get-passwords.sh - Retrieve client credentials from SOPS UPDATED SCRIPTS: - scripts/deploy-client.sh - Now auto-calls password generator PASSWORD CHANGES: - dev.sops.yaml - Regenerated with unique passwords - green.sops.yaml - Created with unique passwords SECURITY PROPERTIES: - 43-character passwords (258 bits entropy) - Cryptographically secure (openssl rand -base64 32) - Unique across all clients - Stored encrypted with SOPS + age ═══════════════════════════════════════════════════════════════ 🛠️ BUG FIX: Nextcloud Volume Mounting ═══════════════════════════════════════════════════════════════ PROBLEM FIXED: Volume detection was looking for "nextcloud-data-{client}" in device ID, but Hetzner volumes use numeric IDs (scsi-0HC_Volume_104429514). SOLUTION: Simplified detection to find first Hetzner volume (works for all clients): ls -1 /dev/disk/by-id/scsi-0HC_Volume_* | head -1 FIXED FILE: - ansible/roles/nextcloud/tasks/mount-volume.yml:15 ═══════════════════════════════════════════════════════════════ 🐛 BUG FIX: Authentik Invitation Task Safety ═══════════════════════════════════════════════════════════════ PROBLEM FIXED: invitation.yml task crashed when accessing undefined variable attribute (enrollment_blueprint_result.rc when API not ready). SOLUTION: Added safety checks before accessing variable attributes: {{ 'In Progress' if (var is defined and var.rc is defined) else 'Complete' }} FIXED FILE: - ansible/roles/authentik/tasks/invitation.yml:91 ═══════════════════════════════════════════════════════════════ 📝 OTHER CHANGES ═══════════════════════════════════════════════════════════════ GITIGNORE: - Added *.md (except README.md) to exclude deployment reports GREEN CLIENT FILES: - keys/ssh/green.pub - SSH public key for green server - secrets/clients/green.sops.yaml - Encrypted secrets with unique passwords ═══════════════════════════════════════════════════════════════ ✅ IMPACT: All Future Deployments Now Secure & Reliable ═══════════════════════════════════════════════════════════════ FUTURE DEPLOYMENTS: - ✅ Automatically get unique passwords - ✅ Volume mounting works reliably - ✅ Ansible tasks handle API delays gracefully - ✅ No manual intervention required DEPLOYMENT TIME: ~15 minutes (fully automated) AUTOMATION RATE: 95% ═══════════════════════════════════════════════════════════════ 🤖 Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
2026-01-18 17:06:04 +01:00
ls -1 /dev/disk/by-id/scsi-0HC_Volume_* 2>/dev/null | head -1
feat: Use Hetzner Volumes for Nextcloud data storage (issue #18) Implement persistent block storage for Nextcloud user data, separating application and data layers: OpenTofu Changes: - tofu/volumes.tf: Create and attach Hetzner Volumes per client - Configurable size per client (default 100 GB for dev) - ext4 formatted, attached but not auto-mounted - tofu/variables.tf: Add nextcloud_volume_size to client config - tofu/terraform.tfvars: Set volume size for dev client (100 GB ~€5.40/mo) Ansible Changes: - ansible/roles/nextcloud/tasks/mount-volume.yml: New mount tasks - Detect volume device automatically - Format if needed, mount at /mnt/nextcloud-data - Add to fstab for persistence - Set correct permissions for www-data - ansible/roles/nextcloud/tasks/main.yml: Include volume mounting - ansible/roles/nextcloud/templates/docker-compose.nextcloud.yml.j2: - Use host mount /mnt/nextcloud-data/data instead of Docker volume - Keep app code in Docker volume (nextcloud-app) - User data now on Hetzner Volume Scripts: - scripts/resize-client-volume.sh: Online volume resizing - Resize via Hetzner API - Expand filesystem automatically - Show cost impact - Verify new size Documentation: - docs/storage-architecture.md: Complete storage guide - Architecture diagrams - Volume specifications - Sizing guidelines - Operations procedures - Performance considerations - Troubleshooting guide - docs/volume-migration.md: Step-by-step migration - Safe migration from Docker volumes - Rollback procedures - Verification checklist - Timeline estimates Benefits: ✅ Data independent from server instance ✅ Resize storage without rebuilding server ✅ Easy data migration between servers ✅ Better separation of concerns (app vs data) ✅ Simplified backup strategy ✅ Cost-optimized (pay for what you use) Volume Pricing: - 50 GB: ~€2.70/month - 100 GB: ~€5.40/month - 250 GB: ~€13.50/month - Resizable online, no downtime Note: Existing clients require manual migration Follow docs/volume-migration.md for safe migration procedure Closes #18 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
2026-01-17 21:07:48 +01:00
register: volume_device_result
changed_when: false
🚀 GREEN CLIENT DEPLOYMENT + CRITICAL SECURITY FIXES ═══════════════════════════════════════════════════════════════ ✅ COMPLETED: Green Client Deployment (green.vrije.cloud) ═══════════════════════════════════════════════════════════════ Services deployed and operational: - Traefik (reverse proxy with SSL) - Authentik SSO (auth.green.vrije.cloud) - Nextcloud (nextcloud.green.vrije.cloud) - Collabora Office (online document editing) - PostgreSQL databases (Authentik + Nextcloud) - Redis (caching + file locking) ═══════════════════════════════════════════════════════════════ 🔐 CRITICAL SECURITY FIX: Unique Passwords Per Client ═══════════════════════════════════════════════════════════════ PROBLEM FIXED: All clients were using IDENTICAL passwords from template (critical vulnerability). If one server compromised, all servers compromised. SOLUTION IMPLEMENTED: ✅ Auto-generate unique passwords per client ✅ Store securely in SOPS-encrypted files ✅ Easy retrieval with get-passwords.sh script NEW SCRIPTS: - scripts/generate-passwords.sh - Auto-generate unique 43-char passwords - scripts/get-passwords.sh - Retrieve client credentials from SOPS UPDATED SCRIPTS: - scripts/deploy-client.sh - Now auto-calls password generator PASSWORD CHANGES: - dev.sops.yaml - Regenerated with unique passwords - green.sops.yaml - Created with unique passwords SECURITY PROPERTIES: - 43-character passwords (258 bits entropy) - Cryptographically secure (openssl rand -base64 32) - Unique across all clients - Stored encrypted with SOPS + age ═══════════════════════════════════════════════════════════════ 🛠️ BUG FIX: Nextcloud Volume Mounting ═══════════════════════════════════════════════════════════════ PROBLEM FIXED: Volume detection was looking for "nextcloud-data-{client}" in device ID, but Hetzner volumes use numeric IDs (scsi-0HC_Volume_104429514). SOLUTION: Simplified detection to find first Hetzner volume (works for all clients): ls -1 /dev/disk/by-id/scsi-0HC_Volume_* | head -1 FIXED FILE: - ansible/roles/nextcloud/tasks/mount-volume.yml:15 ═══════════════════════════════════════════════════════════════ 🐛 BUG FIX: Authentik Invitation Task Safety ═══════════════════════════════════════════════════════════════ PROBLEM FIXED: invitation.yml task crashed when accessing undefined variable attribute (enrollment_blueprint_result.rc when API not ready). SOLUTION: Added safety checks before accessing variable attributes: {{ 'In Progress' if (var is defined and var.rc is defined) else 'Complete' }} FIXED FILE: - ansible/roles/authentik/tasks/invitation.yml:91 ═══════════════════════════════════════════════════════════════ 📝 OTHER CHANGES ═══════════════════════════════════════════════════════════════ GITIGNORE: - Added *.md (except README.md) to exclude deployment reports GREEN CLIENT FILES: - keys/ssh/green.pub - SSH public key for green server - secrets/clients/green.sops.yaml - Encrypted secrets with unique passwords ═══════════════════════════════════════════════════════════════ ✅ IMPACT: All Future Deployments Now Secure & Reliable ═══════════════════════════════════════════════════════════════ FUTURE DEPLOYMENTS: - ✅ Automatically get unique passwords - ✅ Volume mounting works reliably - ✅ Ansible tasks handle API delays gracefully - ✅ No manual intervention required DEPLOYMENT TIME: ~15 minutes (fully automated) AUTOMATION RATE: 95% ═══════════════════════════════════════════════════════════════ 🤖 Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
2026-01-18 17:06:04 +01:00
failed_when: false
feat: Use Hetzner Volumes for Nextcloud data storage (issue #18) Implement persistent block storage for Nextcloud user data, separating application and data layers: OpenTofu Changes: - tofu/volumes.tf: Create and attach Hetzner Volumes per client - Configurable size per client (default 100 GB for dev) - ext4 formatted, attached but not auto-mounted - tofu/variables.tf: Add nextcloud_volume_size to client config - tofu/terraform.tfvars: Set volume size for dev client (100 GB ~€5.40/mo) Ansible Changes: - ansible/roles/nextcloud/tasks/mount-volume.yml: New mount tasks - Detect volume device automatically - Format if needed, mount at /mnt/nextcloud-data - Add to fstab for persistence - Set correct permissions for www-data - ansible/roles/nextcloud/tasks/main.yml: Include volume mounting - ansible/roles/nextcloud/templates/docker-compose.nextcloud.yml.j2: - Use host mount /mnt/nextcloud-data/data instead of Docker volume - Keep app code in Docker volume (nextcloud-app) - User data now on Hetzner Volume Scripts: - scripts/resize-client-volume.sh: Online volume resizing - Resize via Hetzner API - Expand filesystem automatically - Show cost impact - Verify new size Documentation: - docs/storage-architecture.md: Complete storage guide - Architecture diagrams - Volume specifications - Sizing guidelines - Operations procedures - Performance considerations - Troubleshooting guide - docs/volume-migration.md: Step-by-step migration - Safe migration from Docker volumes - Rollback procedures - Verification checklist - Timeline estimates Benefits: ✅ Data independent from server instance ✅ Resize storage without rebuilding server ✅ Easy data migration between servers ✅ Better separation of concerns (app vs data) ✅ Simplified backup strategy ✅ Cost-optimized (pay for what you use) Volume Pricing: - 50 GB: ~€2.70/month - 100 GB: ~€5.40/month - 250 GB: ~€13.50/month - Resizable online, no downtime Note: Existing clients require manual migration Follow docs/volume-migration.md for safe migration procedure Closes #18 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
2026-01-17 21:07:48 +01:00
- name: Set volume device fact
set_fact:
volume_device: "{{ volume_device_result.stdout }}"
- name: Display found volume device
debug:
msg: "Found Nextcloud volume at: {{ volume_device }}"
- name: Check if volume is already formatted
shell: |
blkid {{ volume_device }} | grep -q 'TYPE="ext4"'
register: volume_formatted
changed_when: false
failed_when: false
- name: Format volume as ext4 if not formatted
filesystem:
fstype: ext4
dev: "{{ volume_device }}"
when: volume_formatted.rc != 0
- name: Create mount point directory
file:
path: /mnt/nextcloud-data
state: directory
mode: '0755'
- name: Mount Nextcloud data volume
mount:
path: /mnt/nextcloud-data
src: "{{ volume_device }}"
fstype: ext4
state: mounted
opts: defaults,discard
register: mount_result
- name: Ensure mount persists across reboots
mount:
path: /mnt/nextcloud-data
src: "{{ volume_device }}"
fstype: ext4
state: present
opts: defaults,discard
- name: Create Nextcloud data directory on volume
file:
path: /mnt/nextcloud-data/data
state: directory
owner: www-data
group: www-data
mode: '0750'
- name: Display mount success
debug:
msg: "Nextcloud volume successfully mounted at /mnt/nextcloud-data"