mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2025-10-23 22:45:39 +00:00
Nginx Docker Cert Deploy Role
🎉 Author: Kevin Veen-Birkenbach
This Ansible role simplifies the deployment of Let's Encrypt certificates into Docker Compose setups with Nginx. It supports both individual certificates per subdomain and a single wildcard certificate for all subdomains.
🚀 Features
- Automatically deploys Let's Encrypt certificates to Docker Compose setups.
- Supports both single-domain certificates and one wildcard certificate for all subdomains.
- Copies certificates to the target directory inside the container.
- Automatically reloads or restarts Nginx services when certificates are updated.
- Configures and manages a
systemdservice for automated certificate deployment. - Includes a
systemdtimer for scheduled renewals. - Handles dependent services like
systemd-notifier.
🔧 Tasks Overview
1️⃣ Main Tasks
-
Add Deployment Script
- Copies
nginx-docker-cert-deploy.shto the administrator scripts directory.
- Copies
-
Create Certificate Directory
- Ensures
cert_mount_directoryexists with proper permissions.
- Ensures
-
Configure
systemdService- Deploys a
systemdservice file for the deployment process.
- Deploys a
-
Include
systemd-timerRole- Schedules automatic certificate deployment using a
systemdtimer.
- Schedules automatic certificate deployment using a
2️⃣ Handlers
- Restart Nginx Service
- Restarts
nginx-docker-cert-deploywhenever a certificate update occurs.
- Restarts
🔧 Deploying Certificates into Docker Containers
The role automates copying certificates into Docker Compose setups.
1️⃣ Deployment Script (nginx-docker-cert-deploy.sh)
This script:
- Copies certificates to the correct container directory.
- Reloads Nginx inside all running containers.
- Restarts containers if needed.
Usage:
sh nginx-docker-cert-deploy.sh primary_domain /path/to/docker/compose
🎯 Summary
| Feature | Description |
|---|---|
| Single-domain & wildcard support | Use individual certs or a wildcard certificate |
| Automated renewal | Cronjob or systemd timer ensures auto-renewals |
| Docker-ready | Deploys certificates directly into Docker containers |
| Supports Nginx & Mailu | Compatible with multiple services |
| Systemd integration | Automates deployment via systemd |
🚀 Now your Nginx setup is fully automated and secured with Let's Encrypt! 🎉