summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2022-01-03 22:15:39 +0100
committerHugo Hörnquist <hugo@lysator.liu.se>2022-01-03 22:21:50 +0100
commite086bd549a0bb6cc848a4d768003d7607f6e7624 (patch)
treedeea830cb90077536e7a88f9b0d3af5a9677a0b5
parentBlog working. (diff)
downloadwebsite_blog_2-e086bd549a0bb6cc848a4d768003d7607f6e7624.tar.gz
website_blog_2-e086bd549a0bb6cc848a4d768003d7607f6e7624.tar.xz
stuff
-rw-r--r--files/special-files.ini0
-rw-r--r--manifests/blog.pp6
-rw-r--r--manifests/init.pp78
-rw-r--r--manifests/instance.pp129
-rw-r--r--templates/settings.php.epp13
-rw-r--r--templates/special-files.ini.epp16
6 files changed, 164 insertions, 78 deletions
diff --git a/files/special-files.ini b/files/special-files.ini
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/files/special-files.ini
diff --git a/manifests/blog.pp b/manifests/blog.pp
new file mode 100644
index 0000000..9b5f050
--- /dev/null
+++ b/manifests/blog.pp
@@ -0,0 +1,6 @@
+class blog (
+ String $blog_root,
+ Hash[String,Hash] $blogs = {}
+) {
+ create_resources(blog::instance, $blogs)
+}
diff --git a/manifests/init.pp b/manifests/init.pp
deleted file mode 100644
index a639311..0000000
--- a/manifests/init.pp
+++ /dev/null
@@ -1,78 +0,0 @@
-define blog (
- String $root,
-) {
- vcsrepo { $root:
- ensure => latest,
- provider => git,
- source => 'https://github.com/HugoNikanor/website-blog-2.git',
- revision => 'master',
- # keep_local_changes => true,
- owner => 'hugo',
- group => 'www-data',
- }
-
- vcsrepo { "${root}/entries":
- ensure => latest,
- provider => git,
- source => '/home/git/git/blog-entries.git',
- revision => 'master',
- owner => 'hugo',
- group => 'www-data',
- }
-
- file { "${root}/settings.php":
- ensure => file,
- content => @(EOF)
- <?php
- # FILE MANAGED BY PUPPET
- $author = "Hugo Hornquist";
- $blog_title = "HugoNikanors blogg‽";
- $blog_subtitle = "A blog about nothing, but mostly itself.";
- $http_host = $_SERVER["HTTP_HOST"];
- $urlbase = "http://$http_host/hugo";
- $has_comments = false;
- | EOF
- }
-
- file { "${root}/footnote":
- ensure => directory,
- recurse => true,
- }
-
- $foot_files = [
- ['about.md', 'About'],
- ['contact.md', 'Contact'],
- ['legal.md', 'Legal'],
- ['qna.md', '"Q&amp;A"'],
- ]
-
- $foot_files.each |$item| {
- file { "${root}/footnote/${item[0]}":
- source => "puppet:///modules/blog/footers/${item[0]}",
- }
- }
-
-
- $files_ini = join($foot_files.map |$item| {
- @("EOF")
- files[] = ${item[0]}
- title[] = ${item[1]}
- | EOF
- })
-
- file { "${root}/special-files.ini":
- ensure => file,
- content => @("EOF")
- ; FILE MANAGED BY PUPPET
- ;
- ; Which files on the website that are "special"
- ; This basicly means that they shouldn't have comments
- [footnote]
- ${files_ini}
-
- [other]
- files[] = list
- files[] = entry-not-found.md
- | EOF
- }
-}
diff --git a/manifests/instance.pp b/manifests/instance.pp
new file mode 100644
index 0000000..dfe95be
--- /dev/null
+++ b/manifests/instance.pp
@@ -0,0 +1,129 @@
+define blog::instance (
+ String $blog_title = $name,
+ String $author,
+ Boolean $has_comments = false,
+ String $subtitle = '',
+ Optional[String] $vcs_repo = undef,
+ Optional[String] $domain = undef,
+ Optional[String] $domain_aliases = undef,
+) {
+
+ $root = "${blog::blog_root}/${title}"
+
+ vcsrepo { $root:
+ ensure => latest,
+ provider => git,
+ source => 'https://github.com/HugoNikanor/website-blog-2.git',
+ revision => 'master',
+ # keep_local_changes => true,
+ owner => 'hugo',
+ group => 'www-data',
+ }
+
+ if $vcs_repo {
+ vcsrepo { "${root}/entries":
+ ensure => latest,
+ provider => git,
+ source => $vcs_repo,
+ revision => 'master',
+ owner => 'hugo',
+ group => 'www-data',
+ }
+ } else {
+ file { "${root}/entries":
+ ensure => directory,
+ }
+ }
+
+ file { "${root}/settings.php":
+ ensure => file,
+ content => epp('blog/settings.php.epp', {
+ author => $author,
+ title => $title,
+ subtitle => $subtitle,
+ has_comments => $has_comments,
+ }),
+ }
+
+ file { "${root}/footnote":
+ ensure => directory,
+ recurse => true,
+ }
+
+ $foot_files = [
+ ['about.md', 'About'],
+ ['contact.md', 'Contact'],
+ ['legal.md', 'Legal'],
+ ['qna.md', '"Q&amp;A"'],
+ ]
+
+ $foot_files.each |$item| {
+ file { "${root}/footnote/${item[0]}":
+ source => "puppet:///modules/blog/footers/${item[0]}",
+ }
+ }
+
+ file { "${root}/special-files.ini":
+ ensure => file,
+ content => $foot_files,
+ }
+
+ 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 = {
+ "${blog_title} - server" => $default + $domain_conf,
+ }
+
+ create_resources(nginx::resource::server, $main_conf)
+
+ if $domain_aliases {
+ $alias_conf = {
+ "${blog_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)
+ }
+
+ nginx::resource::location { "${blog_title} - server - /":
+ location => '/',
+ try_files => ['$uri', '$uri/', '=404'],
+ index_files => [],
+ ssl => true,
+ autoindex => on,
+ server => [ "${blog_title} - server", ]
+ }
+
+ nginx::resource::location { "${blog_title} - server - php":
+ location => '~ \.php$',
+ fastcgi_params => 'snippets/fastcgi-php.conf',
+ fastcgi => 'unix:/run/php/php-fpm.sock',
+ ssl => true,
+ server => [ "${blog_title} - server", ],
+ }
+
+ nginx::resource::location { "${blog_title} - server - ht":
+ location => '~ /\.ht',
+ location_cfg_append => { deny => 'all' },
+ index_files => [],
+ ssl => true,
+ server => [ "${blog_title} - server", ],
+ }
+ }
+}
diff --git a/templates/settings.php.epp b/templates/settings.php.epp
new file mode 100644
index 0000000..8f2e62d
--- /dev/null
+++ b/templates/settings.php.epp
@@ -0,0 +1,13 @@
+<%- | String $author,
+ String $title,
+ String $subtitle,
+ Boolean $has_comments = false,
+-%>
+<?php
+# FILE MANAGED BY PUPPET
+$author = "<%= $author %>";
+$blog_title = "<%= $title %>";
+$blog_subtitle = "<%= $subtitle %>";
+$http_host = $_SERVER["HTTP_HOST"];
+$urlbase = "http://$http_host/hugo";
+$has_comments = <%= if $has_comments { 'true' } else { 'false' } %>;
diff --git a/templates/special-files.ini.epp b/templates/special-files.ini.epp
new file mode 100644
index 0000000..66b779a
--- /dev/null
+++ b/templates/special-files.ini.epp
@@ -0,0 +1,16 @@
+<%- | Array[Tuple[String,String]] $foot_files,
+| -%>
+; FILE MANAGED BY PUPPET
+;
+; Which files on the website that are "special"
+; This basicly means that they shouldnt have comments
+[footnote]
+<%- for $foot_files.each |$item| { -%>
+files[] = <%= $item[0] %>
+title[] = <%= $item[1] %>
+<%- } -%>
+
+[other]
+files[] = list
+files[] = entry-not-found.md
+