diff --git a/Modulefile b/Modulefile index 71bb19263f..9bb7198f80 100644 --- a/Modulefile +++ b/Modulefile @@ -9,4 +9,4 @@ project_page 'https://github.com/puppetlabs/puppetlabs-apache' ## Add dependencies, if any: dependency 'puppetlabs/stdlib', '>= 2.4.0' -dependency 'puppetlabs/concat', '>= 1.0.0' +dependency 'puppetlabs/concat', '>= 1.1.0-rc1' diff --git a/manifests/vhost.pp b/manifests/vhost.pp index 641962d582..b5be78a031 100644 --- a/manifests/vhost.pp +++ b/manifests/vhost.pp @@ -1,89 +1,4 @@ -# Definition: apache::vhost -# -# This class installs Apache Virtual Hosts -# -# Parameters: -# - The $port to configure the host on -# - The $docroot provides the DocumentRoot variable -# - The $virtual_docroot provides VirtualDocumentationRoot variable -# - The $serveradmin will specify an email address for Apache that it will -# display when it renders one of it's error pages -# - The $ssl option is set true or false to enable SSL for this Virtual Host -# - The $priority of the site -# - The $servername is the primary name of the virtual host -# - The $serveraliases of the site -# - The $ip to configure the host on, defaulting to * -# - The $options for the given vhost -# - The $override for the given vhost (list of AllowOverride arguments) -# - The $vhost_name for name based virtualhosting, defaulting to * -# - The $logroot specifies the location of the virtual hosts logfiles, default -# to /var/log// -# - The $log_level specifies the verbosity of the error log for this vhost. Not -# set by default for the vhost, instead the global server configuration default -# of 'warn' is used. -# - The $access_log specifies if *_access.log directives should be configured. -# - The $ensure specifies if vhost file is present or absent. -# - The $request_headers is a list of RequestHeader statement strings as per http://httpd.apache.org/docs/2.2/mod/mod_headers.html#requestheader -# - $aliases is a list of Alias hashes for mod_alias as per http://httpd.apache.org/docs/current/mod/mod_alias.html -# each statement is a hash in the form of { alias => '/alias', path => '/real/path/to/directory' } -# - $directories is a lost of hashes for creating statements as per http://httpd.apache.org/docs/2.2/mod/core.html#directory -# each statement is a hash in the form of { path => '/path/to/directory', => } -# see README.md for list of supported directives. -# -# Actions: -# - Install Apache Virtual Hosts -# -# Requires: -# - The apache class -# -# Sample Usage: -# -# # Simple vhost definition: -# apache::vhost { 'site.name.fqdn': -# port => '80', -# docroot => '/path/to/docroot', -# } -# -# # Multiple Mod Rewrites: -# apache::vhost { 'site.name.fqdn': -# port => '80', -# docroot => '/path/to/docroot', -# rewrites => [ -# { -# comment => 'force www domain', -# rewrite_cond => ['%{HTTP_HOST} ^([a-z.]+)?example.com$ [NC]', '%{HTTP_HOST} !^www. [NC]'], -# rewrite_rule => ['.? http://www.%1example.com%{REQUEST_URI} [R=301,L]'] -# }, -# { -# comment => 'prevent image hotlinking', -# rewrite_cond => ['%{HTTP_REFERER} !^$', '%{HTTP_REFERER} !^http://(www.)?example.com/ [NC]'], -# rewrite_rule => ['.(gif|jpg|png)$ - [F]'] -# }, -# ] -# } -# -# # SSL vhost with non-SSL rewrite: -# apache::vhost { 'site.name.fqdn': -# port => '443', -# ssl => true, -# docroot => '/path/to/docroot', -# } -# apache::vhost { 'site.name.fqdn': -# port => '80', -# rewrites => [ -# { -# comment => "redirect non-SSL traffic to SSL site", -# rewrite_cond => ['%{HTTPS} off'], -# rewrite_rule => ['(.*) https://%{HTTPS_HOST}%{REQUEST_URI}'] -# } -# ] -# } -# apache::vhost { 'site.name.fqdn': -# port => '80', -# docroot => '/path/to/other_docroot', -# custom_fragment => template("${module_name}/my_fragment.erb"), -# } -# +# See README.md for more information on usage. define apache::vhost( $docroot, $virtual_docroot = false, @@ -167,6 +82,7 @@ $fastcgi_socket = undef, $fastcgi_dir = undef, $additional_includes = [], + $custom_content = {} ) { # The base class must be included first because it is used by parameter defaults if ! defined(Class['apache']) { @@ -406,86 +322,9 @@ } ] } - # Template uses: - # - $nvh_addr_port - # - $servername - # - $serveradmin - # - $docroot - # - $virtual_docroot - # - $options - # - $override - # - $logroot - # - $name - # - $aliases - # - $_directories - # - $log_level - # - $access_log - # - $access_log_destination - # - $_access_log_format - # - $_access_log_env_var - # - $error_log - # - $error_log_destination - # - $error_documents - # - $fallbackresource - # - $custom_fragment - # - $additional_includes - # block fragment: - # - $block - # directories fragment: - # - $passenger_enabled - # - $php_admin_flags - # - $php_admin_values - # - $directories (a list of key-value hashes is expected) - # fastcgi fragment: - # - $fastcgi_server - # - $fastcgi_socket - # - $fastcgi_dir - # proxy fragment: - # - $proxy_dest - # - $no_proxy_uris - # rack fragment: - # - $rack_base_uris - # redirect fragment: - # - $redirect_source - # - $redirect_dest - # - $redirect_status - # requestheader fragment: - # - $request_headers - # rewrite fragment: - # - $rewrites - # scriptalias fragment: - # - $scriptalias - # - $scriptaliases - # - $ssl - # serveralias fragment: - # - $serveraliases - # setenv fragment: - # - $setenv - # - $setenvif - # ssl fragment: - # - $ssl - # - $ssl_cert - # - $ssl_key - # - $ssl_chain - # - $ssl_certs_dir - # - $ssl_ca - # - $ssl_crl - # - $ssl_crl_path - # - $ssl_verify_client - # - $ssl_verify_depth - # - $ssl_options - # suphp fragment: - # - $suphp_addhandler - # - $suphp_engine - # - $suphp_configpath - # wsgi fragment: - # - $wsgi_daemon_process - # - $wsgi_process_group - # - $wsgi_script_aliases - file { "${priority_real}-${filename}.conf": + concat { "${priority_real}-${filename}.conf": ensure => $ensure, path => "${apache::vhost_dir}/${priority_real}-${filename}.conf", - content => template('apache/vhost.conf.erb'), owner => 'root', group => $apache::params::root_group, mode => '0644', @@ -496,6 +335,301 @@ ], notify => Service['httpd'], } + + # Concat uses: + # nvh_addr_port + # servername + # serveradmin + concat::fragment { "${name}-apache-header": + target => "${priority_real}-${filename}.conf", + order => 01, + content => template('apache/vhost/_header.erb'), + } + # Concat uses: + # virtual_docroot + # docroot + concat::fragment { "${name}-apache-docroot": + target => "${priority_real}-${filename}.conf", + order => 10, + content => template('apache/vhost/_docroot.erb'), + } + + if $aliases { + # Concat uses: + # aliases + # alias_statement + concat::fragment { "${name}-apache-aliases": + target => "${priority_real}-${filename}.conf", + order => 20, + content => template('apache/vhost/_aliases.erb'), + } + } + + if $itk { + # Concat uses: + # itk + concat::fragment { "${name}-apache-itk": + target => "${priority_real}-${filename}.conf", + order => 30, + content => template('apache/vhost/_itk.erb'), + } + } + + if $fallbackresource { + # Concat uses: + # fallbackresource + concat::fragment { "${name}-apache-fallbackresource": + target => "${priority_real}-${filename}.conf", + order => 40, + content => template('apache/vhost/_fallbackresource.erb'), + } + } + + if $_directories { + # Concat uses: + # _directories + concat::fragment { "${name}-apache-directories": + target => "${priority_real}-${filename}.conf", + order => 50, + content => template('apache/vhost/_directories.erb'), + } + } + + if $additional_includes { + # Concat uses: + # additional_includes + concat::fragment { "${name}-apache-additional_includes": + target => "${priority_real}-${filename}.conf", + order => 60, + content => template('apache/vhost/_additional_includes.erb'), + } + } + + if ($log_level or $error_log) { + # Concat uses: + # log_level + # error_log + concat::fragment { "${name}-apache-logging": + target => "${priority_real}-${filename}.conf", + order => 70, + content => template('apache/vhost/_logging.erb'), + } + } + + concat::fragment { "${name}-apache-serversignature": + target => "${priority_real}-${filename}.conf", + order => 80, + content => template('apache/vhost/_serversignature.erb'), + } + + if ($access_log and $_access_log_env_var) { + # Concat uses: + # access_log + # access_log_env_var + concat::fragment { "${name}-apache-accesslog": + target => "${priority_real}-${filename}.conf", + order => 90, + content => template('apache/vhost/_access_log.erb'), + } + } + + if $block != [] { + # Concat uses: + # block + concat::fragment { "${name}-apache-block": + target => "${priority_real}-${filename}.conf", + order => 100, + content => template('apache/vhost/_block.erb'), + } + } + + if $error_documents != [] { + # Concat uses: + # error_documents + concat::fragment { "${name}-apache-error_documents": + target => "${priority_real}-${filename}.conf", + order => 110, + content => template('apache/vhost/_error_document.erb'), + } + } + + if ($proxy_dest or $proxy_pass) { + # Concat uses: + # proxy_dest + # proxy_pass + concat::fragment { "${name}-apache-proxy": + target => "${priority_real}-${filename}.conf", + order => 120, + content => template('apache/vhost/_proxy.erb'), + } + } + + if $rack_base_uris { + # Concat uses: + # rack_base_uris + concat::fragment { "${name}-apache-rack": + target => "${priority_real}-${filename}.conf", + order => 130, + content => template('apache/vhost/_rack.erb'), + } + } + + if ($redirect_source and $redirect_dest) { + # Concat uses: + # redirect_source + # redirect_dest + concat::fragment { "${name}-apache-redirect": + target => "${priority_real}-${filename}.conf", + order => 140, + content => template('apache/vhost/_redirect.erb'), + } + } + + if $rewrites { + # Concat uses: + # rewrites + concat::fragment { "${name}-apache-rewrite": + target => "${priority_real}-${filename}.conf", + order => 150, + content => template('apache/vhost/_rewrite.erb'), + } + } + + if $scriptaliases != [] { + # Concat uses: + # scriptaliases + concat::fragment { "${name}-apache-scriptaliases": + target => "${priority_real}-${filename}.conf", + order => 160, + content => template('apache/vhost/_scriptalias.erb'), + } + } + + if $serveraliases != [] { + # Concat uses: + # serveralias + concat::fragment { "${name}-apache-serveralias": + target => "${priority_real}-${filename}.conf", + order => 170, + content => template('apache/vhost/_serveralias.erb'), + } + } + + if $setenv != [] { + # Concat uses: + # setenv + # setenvif + concat::fragment { "${name}-apache-setenv": + target => "${priority_real}-${filename}.conf", + order => 180, + content => template('apache/vhost/_setenv.erb'), + } + } + + if $ssl { + # Concat uses: + # ssl + # ssl_cert + # ssl_key + # ssl_chain + # ssl_certs_dir + # ssl_ca + # ssl_crl_path + # ssl_crl + # ssl_proxyengine + # ssl_protocol + # ssl_protocol + # ssl_cipher + # ssl_honorcipherorder + # ssl_verify_client + # ssl_verify_depths + concat::fragment { "${name}-apache-ssl": + target => "${priority_real}-${filename}.conf", + order => 190, + content => template('apache/vhost/_ssl.erb'), + } + } + + if $suphp_engine == 'on' { + # Concat uses: + # suphp_engine + # suphp_addhandler + # suphp_configpath + concat::fragment { "${name}-apache-suphp": + target => "${priority_real}-${filename}.conf", + order => 200, + content => template('apache/vhost/_suphp.erb'), + } + } + + if $php_admin_values != [] { + # Concat uses: + # php_admin_values + # php_admin_flags + concat::fragment { "${name}-apache-php_admin": + target => "${priority_real}-${filename}.conf", + order => 210, + content => template('apache/vhost/_php_admin.erb'), + } + } + + if $request_headers { + # Concat uses: + # request_headers + # request_statement + concat::fragment { "${name}-apache-requestheader": + target => "${priority_real}-${filename}.conf", + order => 220, + content => template('apache/vhost/_requestheader.erb'), + } + } + + if ($wsgi_daemon_process and $wsgi_daemon_process_options) { + # Concat uses: + # wsgi_daemon_process + # wsgi_daemon_process_options + # wsgi_process_group + # wsgi_script_aliases + concat::fragment { "${name}-apache-wsgi": + target => "${priority_real}-${filename}.conf", + order => 230, + content => template('apache/vhost/_wsgi.erb'), + } + } + + if $custom_fragment { + # Concat uses: + # custom_fragment + concat::fragment { "${name}-apache-custom_fragment": + target => "${priority_real}-${filename}.conf", + order => 240, + content => template('apache/vhost/_custom_fragment.erb'), + } + } + + if $fastcgi_server { + # Concat uses: + # fastcgi_server + # fastcgi_socket + # fastcgi_dir + concat::fragment { "${name}-apache-fastcgi": + target => "${priority_real}-${filename}.conf", + order => 250, + content => template('apache/vhost/_fastcgi.erb'), + } + } + + concat::fragment { "${name}-apache-footer": + target => "${priority_real}-${filename}.conf", + order => 999, + content => template('apache/vhost/_footer.erb'), + } + + # Allow the passing of additional fragment blocks. + if $custom_content != {} { + create_resources(concat::fragment, $custom_content) + } + if $::osfamily == 'Debian' { $vhost_enable_dir = $apache::vhost_enable_dir $vhost_symlink_ensure = $ensure ? { diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb index 176529fdb7..a16818c07b 100644 --- a/spec/spec_helper_acceptance.rb +++ b/spec/spec_helper_acceptance.rb @@ -32,7 +32,7 @@ on host, puppet('module','install','stahnma/epel'), { :acceptable_exit_codes => [0,1] } end on host, puppet('module','install','puppetlabs-stdlib'), { :acceptable_exit_codes => [0,1] } - on host, puppet('module','install','puppetlabs-concat'), { :acceptable_exit_codes => [0,1] } + on host, puppet('module','install','puppetlabs-concat', '--version=1.1.0-rc1'), { :acceptable_exit_codes => [0,1] } end end end diff --git a/templates/vhost.conf.erb b/templates/vhost.conf.erb deleted file mode 100644 index ea10143f7d..0000000000 --- a/templates/vhost.conf.erb +++ /dev/null @@ -1,63 +0,0 @@ -# ************************************ -# Vhost template in module puppetlabs-apache -# Managed by Puppet -# ************************************ - -> - ServerName <%= @servername %> -<% if @serveradmin -%> - ServerAdmin <%= @serveradmin %> -<% end -%> - - ## Vhost docroot -<% if @virtual_docroot -%> - VirtualDocumentRoot <%= @virtual_docroot %> -<% else -%> - DocumentRoot <%= @docroot %> -<% end -%> -<%= scope.function_template(['apache/vhost/_aliases.erb']) -%> - -<%= scope.function_template(['apache/vhost/_itk.erb']) -%> - -<% if @fallbackresource -%> - FallbackResource <%= @fallbackresource %> -<% end -%> - - ## Directories, there should at least be a declaration for <%= @docroot %> -<%= scope.function_template(['apache/vhost/_directories.erb']) -%> - - ## Load additional static includes -<% Array(@additional_includes).each do |include| %> - Include <%= include %> -<% end %> - - ## Logging -<% if @error_log -%> - ErrorLog <%= @error_log_destination %> -<% end -%> -<% if @log_level -%> - LogLevel <%= @log_level %> -<% end -%> - ServerSignature Off -<% if @access_log and @_access_log_env_var -%> - CustomLog <%= @access_log_destination %> <%= @_access_log_format %> <%= @_access_log_env_var %> -<% elsif @access_log -%> - CustomLog <%= @access_log_destination %> <%= @_access_log_format %> -<% end -%> -<%= scope.function_template(['apache/vhost/_block.erb']) -%> -<%= scope.function_template(['apache/vhost/_error_document.erb']) -%> -<%= scope.function_template(['apache/vhost/_proxy.erb']) -%> -<%= scope.function_template(['apache/vhost/_rack.erb']) -%> -<%= scope.function_template(['apache/vhost/_redirect.erb']) -%> -<%= scope.function_template(['apache/vhost/_rewrite.erb']) -%> -<%= scope.function_template(['apache/vhost/_scriptalias.erb']) -%> -<%= scope.function_template(['apache/vhost/_serveralias.erb']) -%> -<%= scope.function_template(['apache/vhost/_setenv.erb']) -%> -<%= scope.function_template(['apache/vhost/_ssl.erb']) -%> -<%= scope.function_template(['apache/vhost/_suphp.erb']) -%> -<%= scope.function_template(['apache/vhost/_php_admin.erb']) -%> -<%= scope.function_template(['apache/vhost/_requestheader.erb']) -%> -<%= scope.function_template(['apache/vhost/_wsgi.erb']) -%> -<%= scope.function_template(['apache/vhost/_custom_fragment.erb']) -%> -<%= scope.function_template(['apache/vhost/_fastcgi.erb']) -%> - diff --git a/templates/vhost/_access_log.erb b/templates/vhost/_access_log.erb new file mode 100644 index 0000000000..6b100177bc --- /dev/null +++ b/templates/vhost/_access_log.erb @@ -0,0 +1,5 @@ +<% if @access_log and @_access_log_env_var -%> + CustomLog <%= @access_log_destination %> <%= @_access_log_format %> <%= @_access_log_env_var %> +<% elsif @access_log -%> + CustomLog <%= @access_log_destination %> <%= @_access_log_format %> +<% end -%> diff --git a/templates/vhost/_additional_includes.erb b/templates/vhost/_additional_includes.erb new file mode 100644 index 0000000000..99079682b9 --- /dev/null +++ b/templates/vhost/_additional_includes.erb @@ -0,0 +1,5 @@ + + ## Load additional static includes +<% Array(@additional_includes).each do |include| %> + Include <%= include %> +<% end %> diff --git a/templates/vhost/_directories.erb b/templates/vhost/_directories.erb index 66a97dec83..d51a37b57e 100644 --- a/templates/vhost/_directories.erb +++ b/templates/vhost/_directories.erb @@ -1,3 +1,5 @@ + + ## Directories, there should at least be a declaration for <%= @docroot %> <% if @_directories and ! @_directories.empty? -%> <%- [@_directories].flatten.compact.each do |directory| -%> <%- if directory['path'] and directory['path'] != '' -%> diff --git a/templates/vhost/_docroot.erb b/templates/vhost/_docroot.erb new file mode 100644 index 0000000000..dd522e92da --- /dev/null +++ b/templates/vhost/_docroot.erb @@ -0,0 +1,6 @@ + ## Vhost docroot +<% if @virtual_docroot -%> + VirtualDocumentRoot <%= @virtual_docroot %> +<% else -%> + DocumentRoot <%= @docroot %> +<% end -%> diff --git a/templates/vhost/_fallbackresource.erb b/templates/vhost/_fallbackresource.erb new file mode 100644 index 0000000000..ddb023c5ef --- /dev/null +++ b/templates/vhost/_fallbackresource.erb @@ -0,0 +1,3 @@ +<% if @fallbackresource -%> + FallbackResource <%= @fallbackresource %> +<% end -%> diff --git a/templates/vhost/_footer.erb b/templates/vhost/_footer.erb new file mode 100644 index 0000000000..84035efa47 --- /dev/null +++ b/templates/vhost/_footer.erb @@ -0,0 +1 @@ + diff --git a/templates/vhost/_header.erb b/templates/vhost/_header.erb new file mode 100644 index 0000000000..e6f2f95e76 --- /dev/null +++ b/templates/vhost/_header.erb @@ -0,0 +1,10 @@ +# ************************************ +# Vhost template in module puppetlabs-apache +# Managed by Puppet +# ************************************ + +> + ServerName <%= @servername %> +<% if @serveradmin -%> + ServerAdmin <%= @serveradmin %> +<% end -%> diff --git a/templates/vhost/_logging.erb b/templates/vhost/_logging.erb new file mode 100644 index 0000000000..33f1fab46f --- /dev/null +++ b/templates/vhost/_logging.erb @@ -0,0 +1,8 @@ + + ## Logging +<% if @error_log -%> + ErrorLog <%= @error_log_destination %> +<% end -%> +<% if @log_level -%> + LogLevel <%= @log_level %> +<% end -%> diff --git a/templates/vhost/_serversignature.erb b/templates/vhost/_serversignature.erb new file mode 100644 index 0000000000..ff13aaf452 --- /dev/null +++ b/templates/vhost/_serversignature.erb @@ -0,0 +1 @@ + ServerSignature Off