When creating a new site that uses a letsencrypt certificate, the non-ssl version needs to be deployed and run before the SSL configuration can be added and deployed.
e.g.
apache::vhost { "${servername}":
servername => $servername,
port => 80,
docroot => $docroot,
block => 'scm',
rewrites => [
{
comment => 'redirect non-SSL traffic to SSL site except letsencrypt',
rewrite_cond => ['%{HTTPS} off', '%{REQUEST_URI} !^/.well-known/acme-challenge'],
rewrite_rule => ['(.*) https://%{HTTP_HOST}%{REQUEST_URI}'],
}
],
}
->letsencrypt::certonly { "${servername}":
plugin => 'webroot',
webroot_paths => [$docroot],
domains => [$servername],
manage_cron => true,
cron_hour => [0,12],
cron_minute => '30',
cron_success_command => '/bin/systemctl reload apache2.service',
}
# This can't be uncommented on the first run as apache will fail due the files not existing yet
#apache::vhost { "${servername}-ssl":
# servername => $servername,
# port => 443,
# docroot => $docroot,
# block => 'scm',
# ssl => true,
# ssl_cert => "${$facts['letsencrypt_directory'][$servername]}/fullchain.pem",
# ssl_key => "${$facts['letsencrypt_directory'][$servername]}/privkey.pem",
#}
Describe the Solution You Would Like
Allow a vhost to be added and processed after apache has started
Describe Alternatives You've Considered
I've tried using puppet stages but this doesn't work, and also looked at transition but that doesn't seem to be quite what I need
The letsencrypt module provides facts so you can look at that. You can also look at mod_md which natively integrates certificate retrieval into Apache and removes the need for external management
Use Case
When creating a new site that uses a letsencrypt certificate, the non-ssl version needs to be deployed and run before the SSL configuration can be added and deployed. e.g.
Describe the Solution You Would Like
Allow a vhost to be added and processed after apache has started
Describe Alternatives You've Considered
I've tried using puppet stages but this doesn't work, and also looked at transition but that doesn't seem to be quite what I need