Add let's encrypt module

This commit is contained in:
Antonio J. Delgado 2023-11-29 16:56:16 +02:00
parent 0ae01e959a
commit d7274d50db
2 changed files with 16 additions and 6 deletions

View file

@ -54,6 +54,9 @@
# [*users*] # [*users*]
# List of hashes with users information. # List of hashes with users information.
# #
# [*cert_admin_mail*]
# Email to provide to Let's Encrypt in exchange for SSL certificates
#
class mastodon ( class mastodon (
String $ensure = 'present', String $ensure = 'present',
String $hostname = 'mastodon.example.org', String $hostname = 'mastodon.example.org',
@ -94,6 +97,7 @@ class mastodon (
'SESSION_RETENTION_PERIOD' => 31556952, 'SESSION_RETENTION_PERIOD' => 31556952,
}, },
Array $users = [], Array $users = [],
String $cert_admin_mail = 'cert-admin@example.org',
) { ) {
case $ensure { case $ensure {
default: { default: {
@ -118,7 +122,6 @@ class mastodon (
'bison', 'bison',
'build-essential', 'build-essential',
'ca-certificates', 'ca-certificates',
'certbot',
'ffmpeg', 'ffmpeg',
'file', 'file',
'g++', 'g++',
@ -144,7 +147,6 @@ class mastodon (
'pkg-config', 'pkg-config',
# 'postgresql-contrib', # 'postgresql-contrib',
'protobuf-compiler', 'protobuf-compiler',
'python3-certbot-apache',
# 'redis-tools', # 'redis-tools',
'wget', 'wget',
'zlib1g-dev', 'zlib1g-dev',
@ -324,10 +326,14 @@ class mastodon (
timeout => 0, timeout => 0,
require => File["${mastodon_home}/live/.env.production"], require => File["${mastodon_home}/live/.env.production"],
} }
exec { "register-${hostname}-letsencrypt": class { 'letsencrypt':
command => "/etc/init.d/apache2 stop && /usr/bin/certbot certonly --agree-tos --email certs@susurrando.com -d ${hostname} -n --standalone && /etc/init.d/apache2 start", email => $cert_admin_mail,
creates => "/etc/letsencrypt/live/${hostname}/privkey.pem", renew_cron_ensure => 'present',
require => Package['python3-certbot-apache'], }
letsencrypt::certonly { $hostname:
domains => [$hostname],
pre_hook_commands => ['systemctl stop apache2'],
post_hook_commands => ['systemctl start apache2'],
} }
apache::vhost { $hostname: apache::vhost { $hostname:
ensure => $ensure, ensure => $ensure,

View file

@ -29,6 +29,10 @@
{ {
"name": "puppet-systemd", "name": "puppet-systemd",
"version_requirement": "4.0.1" "version_requirement": "4.0.1"
},
{
"name": "puppet-letsencrypt",
"version_requirement": "10.1.0"
} }
], ],
"operatingsystem_support": [ "operatingsystem_support": [