]> git.donarmstrong.com Git - dsa-puppet.git/blob - 3rdparty/modules/apache/manifests/custom_config.pp
add Openstack modules to 3rdparty
[dsa-puppet.git] / 3rdparty / modules / apache / manifests / custom_config.pp
1 # See README.md for usage information
2 define apache::custom_config (
3   $ensure         = 'present',
4   $confdir        = $::apache::confd_dir,
5   $content        = undef,
6   $priority       = '25',
7   $source         = undef,
8   $verify_command = $::apache::params::verify_command,
9   $verify_config  = true,
10 ) {
11
12   if $content and $source {
13     fail('Only one of $content and $source can be specified.')
14   }
15
16   if $ensure == 'present' and ! $content and ! $source {
17     fail('One of $content and $source must be specified.')
18   }
19
20   validate_re($ensure, '^(present|absent)$',
21   "${ensure} is not supported for ensure.
22   Allowed values are 'present' and 'absent'.")
23
24   validate_bool($verify_config)
25
26   if $priority {
27     $priority_prefix = "${priority}-"
28   } else {
29     $priority_prefix = ''
30   }
31
32   ## Apache include does not always work with spaces in the filename
33   $filename_middle = regsubst($name, ' ', '_', 'G')
34   $filename = "${priority_prefix}${filename_middle}.conf"
35
36   if ! $verify_config or $ensure == 'absent' {
37     $notifies = Class['Apache::Service']
38   } else {
39     $notifies = undef
40   }
41
42   file { "apache_${name}":
43     ensure  => $ensure,
44     path    => "${confdir}/${filename}",
45     content => $content,
46     source  => $source,
47     require => Package['httpd'],
48     notify  => $notifies,
49   }
50
51   if $ensure == 'present' and $verify_config {
52     exec { "service notify for ${name}":
53       command     => $verify_command,
54       subscribe   => File["apache_${name}"],
55       refreshonly => true,
56       notify      => Class['Apache::Service'],
57       before      => Exec["remove ${name} if invalid"],
58     }
59
60     exec { "remove ${name} if invalid":
61       command     => "/bin/rm ${confdir}/${filename}",
62       unless      => $verify_command,
63       subscribe   => File["apache_${name}"],
64       refreshonly => true,
65     }
66   }
67 }