summaryrefslogtreecommitdiff
path: root/puppet/modules/apache/manifests/config/file.pp
blob: 7b0586912dd426ed58ffd033c4a4b2035a622426 (plain)
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# deploy apache configuration file
# by default we assume it's a global configuration file
define apache::config::file(
  $ensure     = present,
  $target     = false,
  $type       = 'global',
  $source     = 'absent',
  $content    = 'absent',
  $destination = 'absent'
){
  case $type {
    'include': { $confdir = 'include.d' }
    'global': { $confdir = 'conf.d' }
    default: { fail("Wrong config file type specified for ${name}") }
  }
  $real_destination = $destination ? {
    'absent'  => $::operatingsystem ? {
      centos    => "${apache::centos::config_dir}/${confdir}/${name}",
      gentoo    => "${apache::gentoo::config_dir}/${name}",
      debian    => "${apache::debian::config_dir}/${confdir}/${name}",
      ubuntu    => "${apache::ubuntu::config_dir}/${confdir}/${name}",
      openbsd   => "${apache::openbsd::config_dir}/${confdir}/${name}",
      default   => "/etc/apache2/${confdir}/${name}",
    },
    default => $destination
  }
  file{"apache_${name}":
    ensure  => $ensure,
    path    => $real_destination,
    notify  => Service[apache],
    owner   => root,
    group   => 0,
    mode    => '0644';
  }

  case $ensure {
    'absent', 'purged': {
      # We want to avoid all stuff related to source and content
    }
    'link': {
      if $target {
        File["apache_${name}"] {
          target => $target,
        }
      }
    }
    default: {
      case $content {
        'absent': {
          $real_source = $source ? {
            'absent' => [
              "puppet:///modules/site_apache/${confdir}/${::fqdn}/${name}",
              "puppet:///modules/site_apache/${confdir}/${apache::cluster_node}/${name}",
              "puppet:///modules/site_apache/${confdir}/${::operatingsystem}.${::operatingsystemmajrelease}/${name}",
              "puppet:///modules/site_apache/${confdir}/${::operatingsystem}/${name}",
              "puppet:///modules/site_apache/${confdir}/${name}",
              "puppet:///modules/apache/${confdir}/${::operatingsystem}.${::operatingsystemmajrelease}/${name}",
              "puppet:///modules/apache/${confdir}/${::operatingsystem}/${name}",
              "puppet:///modules/apache/${confdir}/${name}"
            ],
            default => $source
          }
          File["apache_${name}"]{
            source => $real_source,
          }
        }
        default: {
          case $content {
            'absent': {
              $real_source = $source ? {
                'absent' => [
                    "puppet:///modules/site-apache/${confdir}/${::fqdn}/${name}",
                    "puppet:///modules/site-apache/${confdir}/${apache::cluster_node}/${name}",
                    "puppet:///modules/site-apache/${confdir}/${::operatingsystem}.${::operatingsystemmajrelease}/${name}",
                    "puppet:///modules/site-apache/${confdir}/${::operatingsystem}/${name}",
                    "puppet:///modules/site-apache/${confdir}/${name}",
                    "puppet:///modules/apache/${confdir}/${::operatingsystem}.${::operatingsystemmajrelease}/${name}",
                    "puppet:///modules/apache/${confdir}/${::operatingsystem}/${name}",
                    "puppet:///modules/apache/${confdir}/${name}"
                ],
                default => $source,
              }
              File["apache_${name}"]{
                source => $real_source,
              }
            }
            default: {
              File["apache_${name}"]{
                content => $content,
              }
            }
          }
        }
      }
    }
  }

  case $::operatingsystem {
    openbsd: { info("no package dependency on ${::operatingsystem} for ${name}") }
    default: {
      File["apache_${name}"]{
        require => Package[apache],
      }
    }
  }
}