BryanDavis has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/78401


Change subject: Add apache::config puppet class.
......................................................................

Add apache::config puppet class.

Adds a puppet class that that can be used to manage per-vhost apache
configuration snippets. Snippets are stored in /etc/apache2/site-conf.d and
organized by site (vhost) name. When used the base vhost configuration needs
to be modified to `Include` the snippets at runtime.

This feature was originally included in gerrit:78260 but has been extracted
into this discrete patch to keep history cleaner.

Change-Id: I7786f096abaaa620f005858c3f57de8f05391d9a
---
A puppet/modules/apache/manifests/config.pp
M puppet/modules/apache/manifests/init.pp
M puppet/modules/apache/manifests/site.pp
A puppet/modules/apache/templates/site-config.erb
4 files changed, 105 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/vagrant 
refs/changes/01/78401/1

diff --git a/puppet/modules/apache/manifests/config.pp 
b/puppet/modules/apache/manifests/config.pp
new file mode 100644
index 0000000..c4accc8
--- /dev/null
+++ b/puppet/modules/apache/manifests/config.pp
@@ -0,0 +1,83 @@
+# == Define: apache::config
+#
+# This resource type represents a collection of apache configuration
+# directives managed as a config file that can be included from an apache
+# vhost configuration.
+#
+# In order for apache to pickup the configuration files created using this
+# tool you will need to add an 'Include' directive in your base vhost
+# configuration file:
+#
+#   <VirtualHost *>
+#     ...
+#     # Include Puppet managed configuration snippets
+#     Include site-conf.d/my_site_name/*.conf
+#     ...
+#   </VirtualHost>
+#
+# === Parameters
+#
+# [*directives*]
+#   This parameter contains the configuration directives. Directives may be
+#   specified as an array or string. See examples below. Empty by
+#   default.
+#
+# [*site*]
+#   The parameter specifies the apache vhost to apply the configuration to.
+#   Defaults to $mediawiki::wiki_name.
+#
+# [*ensure*]
+#   If 'present' (the default), Puppet will install the config. If
+#   'absent', Puppet will delete its configuration file.
+#
+# [*priority*]
+#   This parameter takes a numeric value, which is used to generate a
+#   prefix for the configuration snippet. Config managed by Puppet will
+#   load in order of priority, with smaller values loading first. The
+#   default is 50. You only need to override the default if you want
+#   these config to load before or after some other config.
+#
+# === Examples
+#
+# The following example configures the thumb.php 404 redirects and
+# illustrates the use of an array to specify config:
+#
+#   apache::config { 'Thumb.php 404':
+#     directives => [
+#       'RewriteCond %{REQUEST_FILENAME} !-f',
+#       'RewriteCond %{REQUEST_FILENAME} !-d',
+#       'RewriteRule 
^/images/thumb/[0-9a-f]/[0-9a-f][0-9a-f]/([^/]+)/([0-9]+)px-.*$ 
/w/thumb.php?f=$1&width=$2 [PT,QSA,B]',
+#       'RewriteCond %{REQUEST_FILENAME} !-f',
+#       'RewriteCond %{REQUEST_FILENAME} !-d',
+#       'RewriteRule 
^/images/thumb/archive/[0-9a-f]/[0-9a-f][0-9a-f]/([^/]+)/([0-9]+)px-.*$ 
/w/thumb.php?f=$1&width=$2&archived=1 [PT,QSA,B]',
+#     ],
+#   }
+#
+# Finally, 'config' can also be specified as a string value. This can be
+# especially powerful when used in combination with Puppet's template()
+# function, as the following example illustrates:
+#
+#   apache::config { 'something cool':
+#     directives => template('cool_config.erb'),
+#   }
+#
+define apache::config(
+    $directives,
+    $site         = $mediawiki::wiki_name,
+    $ensure       = present,
+    $priority     = 50,
+) {
+    include apache
+
+    # make a safe filename based on our title
+    $config_dir = sprintf('%s/%s', $apache::site_config_dir, $site)
+    $fname = inline_template('<%= @title.gsub(/\W/, "-") %>')
+    $config_file = sprintf('%s/%.2d-%s.conf', $config_dir, $priority, $fname)
+
+    file { $config_file:
+        ensure  => $ensure,
+        content => template('apache/site-config.erb'),
+        require => Package['apache2'],
+        notify  => Service['apache2'],
+    }
+}
diff --git a/puppet/modules/apache/manifests/init.pp 
b/puppet/modules/apache/manifests/init.pp
index 675c470..933ee0c 100644
--- a/puppet/modules/apache/manifests/init.pp
+++ b/puppet/modules/apache/manifests/init.pp
@@ -3,6 +3,9 @@
 # Configures Apache HTTP Server
 #
 class apache {
+    # directory for site specific configuration snippets
+    $site_config_dir = '/etc/apache2/site-conf.d'
+
     package { 'apache2':
         ensure  => present,
     }
@@ -25,6 +28,10 @@
         notify  => Service['apache2'],
     }
 
+    file { $apache::site_config_dir:
+        ensure => directory,
+    }
+
     service { 'apache2':
         ensure     => running,
         provider   => 'init',
@@ -34,4 +41,5 @@
 
      Apache::Mod <| |>
      Apache::Site <| |>
+     Apache::Config <| |>
 }
diff --git a/puppet/modules/apache/manifests/site.pp 
b/puppet/modules/apache/manifests/site.pp
index 0c6bca0..473b682 100644
--- a/puppet/modules/apache/manifests/site.pp
+++ b/puppet/modules/apache/manifests/site.pp
@@ -46,6 +46,9 @@
                     before  => Exec["enable ${site}"],
                 }
             }
+            file { "${apache::site_config_dir}/${site_file}":
+                ensure => directory,
+            }
             exec { "enable ${title}":
                 command => "a2ensite -qf ${site}",
                 unless  => "test -L /etc/apache2/sites-enabled/${site_file}",
diff --git a/puppet/modules/apache/templates/site-config.erb 
b/puppet/modules/apache/templates/site-config.erb
new file mode 100644
index 0000000..daf9d64
--- /dev/null
+++ b/puppet/modules/apache/templates/site-config.erb
@@ -0,0 +1,11 @@
+# Apache settings for <%= @site %>: <%= @title.tr('_', ' ') %>.
+# This file is managed by Puppet.
+
+<%=
+case @directives
+when Array
+       @directives.join("\n")
+else
+       @directives
+end
+%>

-- 
To view, visit https://gerrit.wikimedia.org/r/78401
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I7786f096abaaa620f005858c3f57de8f05391d9a
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/vagrant
Gerrit-Branch: master
Gerrit-Owner: BryanDavis <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to