initial commit

This commit is contained in:
Ludovic Cartier 2024-12-17 18:04:26 +01:00
parent 81e2115868
commit 0bdd8faa16
4 changed files with 78 additions and 0 deletions

2
defaults/main.yml Normal file
View File

@ -0,0 +1,2 @@
---
letsencryt_email: 'admin@brainsys.io'

36
files/renew-hook Normal file
View File

@ -0,0 +1,36 @@
#!/bin/bash
_logfile="/var/log/renew_ssl.txt"
echo "Date: $(date +%Y%m%d)" | tee -a $_logfile
echo "Nb of args: $?" | tee -a $_logfile
if [ ! -z "$RENEWED_DOMAINS" ]; then
for domain in $RENEWED_DOMAINS; do
if [[ $domain = www.* ]]; then
domain=`echo $domain | sed 's/www.\(.*\)/\1/g'`
else
echo "Processing domain: $domain" | tee -a $_logfile
mkdir -p /etc/haproxy/ssl/archives
if test -f /etc/haproxy/ssl/certs/$domain.pem; then
cp /etc/haproxy/ssl/certs/$domain.pem /etc/haproxy/ssl/archives/$domain.pem.$(date +%Y%m%d)
fi
cat /etc/letsencrypt/live/$domain/privkey.pem /etc/letsencrypt/live/$domain/fullchain.pem > /etc/haproxy/ssl/certs/$domain.pem
# check if pem file in haproxy dir is empty and rm it if it is
if [ ! -s /etc/haproxy/ssl/certs/$domain.pem ]; then
rm /etc/haproxy/ssl/certs/$domain.pem
fi
/usr/sbin/haproxy -c -f /etc/haproxy/haproxy.cfg && /bin/systemctl reload haproxy.service
echo "$domain renewed at $(date)" | tee -a $_logfile
fi
done
else
echo "$domain renewal failed at $(date)" | tee -a $_logfile
exit 0
fi
#/* vim: set tabstop=4:softtabstop=4:shiftwidth=4:noexpandtab */

32
tasks/main.yml Normal file
View File

@ -0,0 +1,32 @@
---
- name: letsencrypt | apt update cache
apt:
update_cache: yes
cache_valid_time: 86400 #One day
- name: letsencrypt | install packages
apt:
name:
- certbot
state: present
- name: letsencrypt | copy configuration files
template:
src: "cli.ini.j2"
dest: "/etc/letsencrypt/cli.ini"
mode: "0644"
force: yes
backup: yes
- name: letsencrypt | create hook directory
file:
path: /usr/local/bin/letsencrypt/
state: directory
owner: root
group: root
- name: letsencrypt | copy renew hook
copy:
src: "renew-hook"
dest: "/usr/local/bin/letsencrypt/renew-hook"
mode: "0755"

8
templates/cli.ini.j2 Normal file
View File

@ -0,0 +1,8 @@
# {{ ansible_managed }}
# Because we are using logrotate for greater flexibility, disable the
# internal certbot logrotation.
max-log-backups = 0
email = {{ letsencrypt_email }}
deploy-hook = /usr/local/bin/letsencrypt/renew-hook
#renew-before-expiry = 20
agree-tos = True