dev/provisioning/modules/apache/manifests/custom_config.pp
changeset 28 b0b56e0f8c7f
equal deleted inserted replaced
27:a2342f26c9de 28:b0b56e0f8c7f
       
     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 { "syntax verification 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       require     => Anchor['::apache::modules_set_up']
       
    59     }
       
    60 
       
    61     exec { "remove ${name} if invalid":
       
    62       command     => "/bin/rm ${confdir}/${filename}",
       
    63       unless      => $verify_command,
       
    64       subscribe   => File["apache_${name}"],
       
    65       refreshonly => true,
       
    66     }
       
    67   }
       
    68 }