puppetlabs / puppetlabs-apache

Puppet module for the Apache httpd server, maintained by Puppet, Inc.
https://forge.puppet.com/modules/puppetlabs/apache
Apache License 2.0
366 stars 1.08k forks source link

Start apache without all vhosts #2509

Open justafish opened 9 months ago

justafish commented 9 months ago

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.

    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

ekohl commented 9 months ago

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