Fix parameter defaults

This patch aims to avoid defaulting parameters to the empty string and
to provide more reasonable default values where possible.

We set the default of $mediawiki::role to 'all' since that is what
Infra uses and is the most reasonable default between 'all', 'app', and
'image-scaler'.

We set the default of $mediawiki::site_hostname to $::fqdn instead of
empty string.

We set the default path of $mediawiki::mediawiki_location and
mediawiki::mediawiki_images_location to have base paths of
/srv/mediawiki since '/srv/mediawiki/w' is the hard-coded directory
path for the mediawiki repo.

We change the $mediawiki::ssl_cert_file and $mediawiki::ssl_key_file to
use the default snakeoil files so that a new user can easily set this
up without having to generate certs. This follows the pattern set by
the puppet-askbot and other modules.

We change the default values of the rest of the parameters from empty
string to undef and fix the logic involving those values.

Change-Id: Ic5271a952659896c75137b546c4b315c53c7511c
This commit is contained in:
Colleen Murphy 2015-08-04 15:40:14 -07:00
parent 3bd7b5030c
commit 670beecdef
2 changed files with 17 additions and 14 deletions

View File

@ -1,16 +1,16 @@
# Class: mediawiki
#
class mediawiki(
$role = '',
$site_hostname = '',
$mediawiki_location = '',
$mediawiki_images_location = '',
$ssl_cert_file = "/etc/ssl/certs/${::fqdn}.pem",
$ssl_key_file = "/etc/ssl/private/${::fqdn}.key",
$ssl_chain_file = '',
$ssl_cert_file_contents = '', # If left empty puppet will not create file.
$ssl_key_file_contents = '', # If left empty puppet will not create file.
$ssl_chain_file_contents = '' # If left empty puppet will not create file.
$role = 'all',
$site_hostname = $::fqdn,
$mediawiki_location = '/srv/mediawiki/w',
$mediawiki_images_location = '/srv/mediawiki/images',
$ssl_cert_file = '/etc/ssl/certs/ssl-cert-snakeoil.pem',
$ssl_key_file = '/etc/ssl/private/ssl-cert-snakeoil.key',
$ssl_chain_file = undef,
$ssl_cert_file_contents = undef, # If left empty puppet will not create file.
$ssl_key_file_contents = undef, # If left empty puppet will not create file.
$ssl_chain_file_contents = undef # If left empty puppet will not create file.
) {
if ($role == 'app' or $role == 'all') {
@ -29,7 +29,7 @@ class mediawiki(
ensure => present,
}
if $ssl_cert_file_contents != '' {
if $ssl_cert_file_contents != undef {
file { $ssl_cert_file:
owner => 'root',
group => 'root',
@ -39,7 +39,7 @@ class mediawiki(
}
}
if $ssl_key_file_contents != '' {
if $ssl_key_file_contents != undef {
file { $ssl_key_file:
owner => 'root',
group => 'ssl-cert',
@ -49,7 +49,7 @@ class mediawiki(
}
}
if $ssl_chain_file_contents != '' {
if $ssl_chain_file_contents != undef {
file { $ssl_chain_file:
owner => 'root',
group => 'root',

View File

@ -42,7 +42,10 @@
SSLProtocol All -SSLv2 -SSLv3
SSLCertificateFile <%= scope.lookupvar("mediawiki::ssl_cert_file") %>
SSLCertificateKeyFile <%= scope.lookupvar("mediawiki::ssl_key_file") %>
<% if scope.lookupvar("mediawiki::ssl_chain_file") != "" %>
<%# The original default was '' -%>
<%# scope.lookupvar returns nil for an undefined variable in puppet 4 -%>
<%# scope.lookupvar returns :undef for an undefined variable in puppet 3 -%>
<% unless ['', nil, :undef].include?(scope.lookupvar("mediawiki::ssl_chain_file")) %>
SSLCertificateChainFile <%= scope.lookupvar("mediawiki::ssl_chain_file") %>
<% end %>