Browse Source

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
Colleen Murphy 11 months ago
parent
commit
e5996fd275
1 changed files with 9 additions and 1 deletions
  1. 9
    1
      manifests/vhost.pp

+ 9
- 1
manifests/vhost.pp View File

@@ -10,6 +10,8 @@
10 10
 #   a firewall should be configured.
11 11
 # - The $template option specifies whether to use the default template or
12 12
 #   override
13
+# - The $content option specifies the exact content of the vhost file;
14
+#   overrides the template parameter
13 15
 # - The $priority of the site
14 16
 # - The $serveraliases of the site
15 17
 # - The $options for the given vhost
@@ -41,6 +43,7 @@ define httpd::vhost(
41 43
     $servername         = $httpd::params::servername,
42 44
     $ssl                = $httpd::params::ssl,
43 45
     $template           = $httpd::params::template,
46
+    $content            = undef,
44 47
     $vhost_name         = $httpd::params::vhost_name,
45 48
   ) {
46 49
 
@@ -87,9 +90,14 @@ define httpd::vhost(
87 90
     }
88 91
   }
89 92
 
93
+  if $content != undef {
94
+    $_content = $content
95
+  } else {
96
+    $_content = template($template)
97
+  }
90 98
   file { "${priority}-${name}.conf":
91 99
       path    => "${httpd::params::vdir}/${priority}-${name}.conf",
92
-      content => template($template),
100
+      content => $_content,
93 101
       owner   => 'root',
94 102
       group   => 'root',
95 103
       mode    => '0755',

Loading…
Cancel
Save