File: fragment.pp

package info (click to toggle)
puppet-module-puppetlabs-apache 12.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,664 kB
  • sloc: ruby: 275; sh: 32; makefile: 2
file content (87 lines) | stat: -rw-r--r-- 2,260 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# @summary Define a fragment within a vhost
#
# @param vhost
#   The title of the vhost resource to append to
#
# @param priority
#   Set the priority to match the one `apache::vhost` sets. This must match the
#   one `apache::vhost` sets or else the concat fragment won't be found.
#
# @param content
#   The content to put in the fragment. Only when it's non-empty the actual
#   fragment will be created.
#
# @param order
#   The order to insert the fragment at
#
# @param port
#   The port to use
#
# @example With a vhost without priority
#   include apache
#   apache::vhost { 'myvhost':
#   }
#   apache::vhost::fragment { 'myfragment':
#     vhost   => 'myvhost',
#     content => '# Foo',
#   }
#
# @example With a vhost with priority
#   include apache
#   apache::vhost { 'myvhost':
#     priority => 42,
#   }
#   apache::vhost::fragment { 'myfragment':
#     vhost    => 'myvhost',
#     priority => 42,
#     content  => '# Foo',
#   }
#
# @example With a vhost with default vhost
#   include apache
#   apache::vhost { 'myvhost':
#     default_vhost => true,
#   }
#   apache::vhost::fragment { 'myfragment':
#     vhost    => 'myvhost',
#     priority => 10, # default_vhost implies priority 10
#     content  => '# Foo',
#   }
#
# @example Adding a fragment to the built in default vhost
#   include apache
#   apache::vhost::fragment { 'myfragment':
#     vhost    => 'default',
#     priority => 15,
#     content  => '# Foo',
#   }
#
define apache::vhost::fragment (
  String[1] $vhost,
  Optional[Stdlib::Port] $port                  = undef,
  Optional[Apache::Vhost::Priority] $priority   = undef,
  Optional[String] $content                     = undef,
  Integer[0] $order                             = 900,
) {
  # This copies the logic from apache::vhost
  if $priority {
    $priority_real = "${priority}-"
  } elsif $priority == false {
    $priority_real = ''
  } else {
    $priority_real = '25-'
  }

  $filename = $port ? {
    Integer => regsubst("${vhost}-${port}", ' ', '_', 'G'),
    Undef   => regsubst($vhost, ' ', '_', 'G'),
  }

  if $content =~ String[1] {
    concat::fragment { "${vhost}-${title}":
      target  => "${priority_real}${filename}.conf",
      order   => $order,
      content => $content,
    }
  }
}