Add lego certificate service to ansible

This commit is contained in:
Tobias Reisinger 2023-12-20 16:00:03 +01:00
parent 5246a6b101
commit 068a8e2cd7
Signed by: serguzim
GPG key ID: 13AD60C237A28DFE
13 changed files with 212 additions and 0 deletions

6
roles/lego/files/hook.sh Normal file
View file

@ -0,0 +1,6 @@
#!/usr/bin/env sh
cp -f "$LEGO_CERT_PATH" /certificates
cp -f "$LEGO_CERT_KEY_PATH" /certificates
exit 33 # special exit code to signal that the certificate has been updated

15
roles/lego/files/lego.sh Executable file
View file

@ -0,0 +1,15 @@
#!/usr/bin/env sh
domain="$1"
action="${2:-renew}"
docker compose run --rm app \
--domains "$domain" \
"$action" \
"--$action-hook" "/config/hook.sh"
if [ "$?" = "33" ] && [ -x "./lego.d/$domain" ];
then
echo "Running hook for $domain"
"./lego.d/$domain"
fi

View file

@ -0,0 +1,10 @@
[Unit]
Description=Renew certificates
[Timer]
Persistent=true
OnCalendar=*-*-* 01:15:00
RandomizedDelaySec=2h
[Install]
WantedBy=timers.target

View file

@ -0,0 +1,16 @@
#!/usr/bin/env sh
domain="db.serguzim.me"
docker compose run --rm app "$1" "$domain"
_install() {
install --owner=postgres --group=postgres --mode=600 \
"/opt/services/_certificates/$domain.$1" \
"/var/lib/postgresql/server.$1"
}
_install crt
_install key
sudo -u postgres pg_ctl -D /var/lib/postgres/data/ reload

View file

@ -0,0 +1,17 @@
#!/usr/bin/env sh
domain="registry.serguzim.me"
docker compose run --rm app "$1" "$domain"
_install() {
install --owner=root --group=root --mode=600 \
"/opt/services/_certificates/$domain.$1" \
"/opt/services/harbor/server.$1"
}
_install crt
_install key
export HARBOR_BUNDLE_DIR=/opt/services/harbor
$HARBOR_BUNDLE_DIR/data/install.sh