From e5996fd2750f2518d175d7bf5cc076d4890f1c23 Mon Sep 17 00:00:00 2001 From: Colleen Murphy Date: Mon, 28 May 2018 14:58:02 -0700 Subject: [PATCH] Add content parameter to httpd::vhost Evaluating the template from the vhost defined type rather than the module where it originates causes problems when dereferencing the variables in the ERB file. If they are not accessed via the internal scope object, they can't be found when using puppet 4. The scope object is also useless when the variables are defined in a defined type and not a class. This patch adds a new parameter, $content, which overrides the $template parameter. If provided, $content indicates the literal string content for the vhost, as opposed to a reference to a template that needs to be rendered. This can be used like this: $content = template('example/example.vhost.erb') httpd::vhost { 'vhostname': content => $content, priority => 50 } This way the template is evaluated when the template() function is called and has access to variables in that scope. Change-Id: Ibe3c609d92f3321f43f4794062a64b119b07a1d0 --- manifests/vhost.pp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/manifests/vhost.pp b/manifests/vhost.pp index 4a32853..25f30cc 100644 --- a/manifests/vhost.pp +++ b/manifests/vhost.pp @@ -10,6 +10,8 @@ # a firewall should be configured. # - The $template option specifies whether to use the default template or # override +# - The $content option specifies the exact content of the vhost file; +# overrides the template parameter # - The $priority of the site # - The $serveraliases of the site # - The $options for the given vhost @@ -41,6 +43,7 @@ define httpd::vhost( $servername = $httpd::params::servername, $ssl = $httpd::params::ssl, $template = $httpd::params::template, + $content = undef, $vhost_name = $httpd::params::vhost_name, ) { @@ -87,9 +90,14 @@ define httpd::vhost( } } + if $content != undef { + $_content = $content + } else { + $_content = template($template) + } file { "${priority}-${name}.conf": path => "${httpd::params::vdir}/${priority}-${name}.conf", - content => template($template), + content => $_content, owner => 'root', group => 'root', mode => '0755',