Fix $site_root and $site_docroot parameters

The $site_root parameter must be set in order for the file resource
ensuring it to work. However, the best default for it depends on the
$site_name and $site_vhosts_root parameter. Class parameter defaults
behave strangely if they depend on another class parameter: they take
on the value of whatever the user has set, not the default value. So if
we want the default value of $site_root to be
"${site_vhosts_root}/${site_name}", and we want it to be acceptable to
use the default value of 'www.example.com' as the site name, then we
have to set the default in the body of the class, not in the parameters
list. The same is true for the $site_docroot parameter.

This patch leaves the official default of $site_root as undef but
conditionally sets a preferred default of "${site_vhosts_root}/${site_name}" in
the body of the class. Since variables in puppet are immutable we need
to assign this value to a new variable and fix the references to this
variable throughout hte module.

This patch changes the official default of $site_docroot from
"${site_root}/w" to undef, because that default would have different
behavior depending on whether the user had set $site_root or not. We
then conditionally set it to the right default in the body of the class
and update references to that variable. Also changed the Directory key
for the docroot in the vhost template to refer to the $docroot
parameter passed in to the httpd::vhost type rather than the
$_site_docroot value from the class, which evaluates to the same value
but makes the Directory tag consistent with the Docroot declaration
above it.

Change-Id: Iaed65b20816c0b4f6fd34f7e0ef07f906bb9750e
This commit is contained in:
Colleen Murphy 2015-10-15 13:09:08 -07:00
parent c67a4231f8
commit 601a5cf31f
3 changed files with 26 additions and 14 deletions

View File

@ -62,13 +62,13 @@
class drupal (
$site_name = $::fqdn,
$site_vhost_root = '/srv/vhosts',
$site_root = undef,
$site_docroot = "${site_root}/w",
$site_docroot = undef,
$site_mysql_host = 'localhost',
$site_mysql_user = undef,
$site_mysql_password = undef,
$site_mysql_database = undef,
$site_vhost_root = '/srv/vhosts',
$site_profile = 'standard',
$site_admin_password = undef,
$site_alias = undef,
@ -92,6 +92,18 @@ class drupal (
include ::httpd
include ::pear
if $site_root == undef {
$_site_root = "${site_vhost_root}/${site_name}"
} else {
$_site_root = $site_root
}
if $site_docroot == undef {
$_site_docroot = "${_site_root}/w"
} else {
$_site_docroot = $site_docroot
}
# ssl certificates
if $site_ssl_enabled == true {
@ -142,12 +154,12 @@ class drupal (
::httpd::vhost { $site_name:
port => 80,
priority => '50',
docroot => $site_docroot,
docroot => $_site_docroot,
require => Exec['init-slot-dirs'],
template => 'drupal/drupal.vhost.erb',
}
file { $site_root:
file { $_site_root:
ensure => directory,
owner => 'root',
group => 'www-data',
@ -159,10 +171,10 @@ class drupal (
# so drush dsd can flip this symlink between slot0/slot1
# (won't be recreated until the symlink exists)
exec { 'init-slot-dirs':
command => "/bin/ln -s ${site_root}/slot1 ${site_docroot}",
unless => "/usr/bin/test -L ${site_docroot}",
command => "/bin/ln -s ${_site_root}/slot1 ${_site_docroot}",
unless => "/usr/bin/test -L ${_site_docroot}",
logoutput => 'on_failure',
require => File[$site_root],
require => File[$_site_root],
}
httpd_mod { 'rewrite':
@ -224,22 +236,22 @@ class drupal (
# site custom configuration
file { "${site_root}/etc":
file { "${_site_root}/etc":
ensure => directory,
owner => 'root',
group => 'root',
mode => '0755',
require => File[$site_root],
require => File[$_site_root],
}
file { "${site_root}/etc/settings.php":
file { "${_site_root}/etc/settings.php":
ensure => file,
owner => 'root',
group => 'root',
mode => '0400',
content => template('drupal/settings.php.erb'),
replace => true,
require => File["${site_root}/etc"],
require => File["${_site_root}/etc"],
}
# deploy a site from scratch when site status is 'NOT INSTALLED'

View File

@ -1,8 +1,8 @@
<?php
$aliases['<%= @site_alias %>'] = array(
'root' => '<%= @site_docroot %>',
'dsd-root' => '<%= @site_root %>',
'root' => '<%= @_site_docroot %>',
'dsd-root' => '<%= @_site_root %>',
'uri' => '<%= @site_base_url %>',
'db-url' => 'mysql://<%= @site_mysql_user %>:<%= @site_mysql_password %>@<%= @site_mysql_host %>/<%= @site_mysql_database %>',
'databases' => array(

View File

@ -27,7 +27,7 @@ NameVirtualHost <%= @vhost_name %>:443
<%= " ServerAlias #{@serveraliases}" %>
<% end -%>
DocumentRoot <%= @docroot %>
<Directory <%= @site_docroot %>>
<Directory <%= @docroot %>>
Options FollowSymLinks MultiViews
AllowOverride None
Order allow,deny