diff --git a/README.md b/README.md index 5066caac9..762689d07 100644 --- a/README.md +++ b/README.md @@ -133,6 +133,7 @@ [`logroot`]: #logroot [Log security]: http://httpd.apache.org/docs/current/logs.html#security +[`manage_docroot`]: #manage_docroot [`manage_user`]: #manage_user [`manage_group`]: #manage_group [`MaxConnectionsPerChild`]: https://httpd.apache.org/docs/current/mod/mpm_common.html#maxconnectionsperchild @@ -1886,6 +1887,8 @@ Sets the list of resources to look for when a client requests an index of the di **Required**. Sets the [`DocumentRoot`][] location, from which Apache serves files. +If `docroot` and [`manage_docroot`][] are both set to `false`, no [`DocumentRoot`][] will be set and the accompanying `` block will not be created. + ##### `docroot_group` Sets group access to the [`docroot`][] directory. Defaults to 'root'. diff --git a/manifests/vhost.pp b/manifests/vhost.pp index 25530bccb..36d425ef1 100644 --- a/manifests/vhost.pp +++ b/manifests/vhost.pp @@ -227,6 +227,12 @@ if $limit_request_field_size { validate_integer($limit_request_field_size) } + + # Validate the docroot as a string if: + # - $manage_docroot is true + if $manage_docroot { + validate_string($docroot) + } # Input validation ends if $ssl and $ensure == 'present' { @@ -271,7 +277,7 @@ # This ensures that the docroot exists # But enables it to be specified across multiple vhost resources - if ! defined(File[$docroot]) and $manage_docroot { + if $manage_docroot and $docroot and ! defined(File[$docroot]) { file { $docroot: ensure => directory, owner => $docroot_owner, @@ -443,7 +449,7 @@ fail("Apache::Vhost[${name}]: 'directories' must be either a Hash or an Array of Hashes") } $_directories = $directories - } else { + } elsif $docroot { $_directory = { provider => 'directory', path => $docroot, @@ -518,10 +524,12 @@ # Template uses: # - $virtual_docroot # - $docroot - concat::fragment { "${name}-docroot": - target => "${priority_real}${filename}.conf", - order => 10, - content => template('apache/vhost/_docroot.erb'), + if $docroot { + concat::fragment { "${name}-docroot": + target => "${priority_real}${filename}.conf", + order => 10, + content => template('apache/vhost/_docroot.erb'), + } } # Template uses: diff --git a/templates/vhost/_docroot.erb b/templates/vhost/_docroot.erb index 6039fa63c..b67998b4b 100644 --- a/templates/vhost/_docroot.erb +++ b/templates/vhost/_docroot.erb @@ -2,6 +2,6 @@ ## Vhost docroot <% if @virtual_docroot -%> VirtualDocumentRoot "<%= @virtual_docroot %>" -<% else -%> +<% elsif @docroot -%> DocumentRoot "<%= @docroot %>" <% end -%>