From cad8f107bf7e81ab143cc7a2cb9660761589eb3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Wed, 5 Jan 2022 05:07:25 +0100 Subject: Move remaining out of site.pp. --- modules/blog/manifests/init.pp | 38 +++++++++++++++++++++++++++++++++++++- modules/blog/manifests/instance.pp | 35 +---------------------------------- 2 files changed, 38 insertions(+), 35 deletions(-) (limited to 'modules/blog/manifests') diff --git a/modules/blog/manifests/init.pp b/modules/blog/manifests/init.pp index 9b5f050..1ecce39 100644 --- a/modules/blog/manifests/init.pp +++ b/modules/blog/manifests/init.pp @@ -1,6 +1,42 @@ class blog ( String $blog_root, - Hash[String,Hash] $blogs = {} + Hash[String,Hash] $blogs = {}, + Optional[String] $domain = undef, + Optional[Array[String]] $domain_aliases = undef, ) { create_resources(blog::instance, $blogs) + + if $domain { + $default = { + access_log => 'absent', + error_log => 'absent', + ssl => true, + ssl_cert => "/etc/letsencrypt/live/${certname}/fullchain.pem", + ssl_key => "/etc/letsencrypt/live/${certname}/privkey.pem", + use_default_location => false, + } + $domain_conf = { + server_name => [ $domain, ], + index_files => [ 'index.php', 'index.html', 'index.htm', ], + www_root => $blog::blog_root, + } + + $main_conf = { + "${safe_title} - server" => $default + $domain_conf, + } + + create_resources(nginx::resource::server, $main_conf) + + if $domain_aliases { + $alias_conf = { + "${safe_title} - aliases" => $default + { + server_name => $domain_aliases, + server_cfg_append => { + 'return' => '301 $scheme://blog.hornquist.se$request_uri', + }, + }, + } + create_resources(nginx::resource::server, $alias_conf) + } + } } diff --git a/modules/blog/manifests/instance.pp b/modules/blog/manifests/instance.pp index 0bbdb32..adaa30d 100644 --- a/modules/blog/manifests/instance.pp +++ b/modules/blog/manifests/instance.pp @@ -4,8 +4,6 @@ define blog::instance ( Boolean $has_comments = false, String $subtitle = '', Optional[String] $vcs_repo = undef, - Optional[String] $domain = undef, - Optional[Array[String]] $domain_aliases = undef, ) { $root = "${blog::blog_root}/${title}" @@ -71,38 +69,7 @@ define blog::instance ( $certname = lookup('certname') - if $domain { - $default = { - access_log => 'absent', - error_log => 'absent', - ssl => true, - ssl_cert => "/etc/letsencrypt/live/${certname}/fullchain.pem", - ssl_key => "/etc/letsencrypt/live/${certname}/privkey.pem", - use_default_location => false, - } - $domain_conf = { - server_name => [ $domain, ], - index_files => [ 'index.php', 'index.html', 'index.htm', ], - www_root => $blog::blog_root, - } - - $main_conf = { - "${safe_title} - server" => $default + $domain_conf, - } - - create_resources(nginx::resource::server, $main_conf) - - if $domain_aliases { - $alias_conf = { - "${safe_title} - aliases" => $default + { - server_name => $domain_aliases, - server_cfg_append => { - 'return' => '301 $scheme://blog.hornquist.se$request_uri', - }, - }, - } - create_resources(nginx::resource::server, $alias_conf) - } + if $blog::domain { nginx::resource::location { "${safe_title} - server - /": location => '/', -- cgit v1.2.3