summaryrefslogtreecommitdiff
path: root/manifests/init.pp
blob: 32b46100da1fffdbd132f70893ab23ac7749111f (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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
# modules/apache/manifests/init.pp
# 2008 - admin(at)immerda.ch
# adapted by Puzzle ITC - haerry+puppet(at)puzzle.ch
# License: GPLv3

import "modules/*.pp"

class apache {
    case $operatingsystem {
        centos: { include apache::centos }
        gentoo: { include apache::gentoo }
        debian: { include apache::debian }
        ubuntu: { include apache::ubuntu }
        default: { include apache::base }
    }
}

class apache::base {

    file{'vhosts_dir':
        path => '/etc/apache2/vhosts.d/',
        ensure => directory,
        owner => root,
        group => 0,
        mode => 0755,
        require => Package[apache],
    }

    package { 'apache':
        name => 'apache',
        ensure => present,
    }

    service { apache:
        name => 'apache2',
        enable => true,
        ensure => running,
        require => Package[apache],
    }
    file { 'default_apache_index':
        path => '/var/www/localhost/htdocs/index.html',
        ensure => file,
        owner => 'root',
        group => 0,
        mode => 644,
        require => Package[apache],
        content => template('apache/default/default_index.erb'),
    }
    include apache::status
}

### distro specific stuff
class apache::centos inherits apache::base{
    $config_dir = '/etc/httpd/'
    Package[apache]{
        name => 'httpd',
    } 
    Service[apache]{
        name => 'httpd'
    }
    package { 'mod_ssl':
        name => 'mod_ssl',
        ensure => present,
        require => Package[apache],
    }
    File[default_apache_index]{
        path => '/var/www/html/index.html',
    }
    File[vhosts_dir]{
        path => "$config_dir/vhosts.d/",
    }

    file{"${config_dir}/conf.d/ZZZ_vhosts.conf":
        source => "puppet://$server/apache/centos/vhosts.conf",
        owner => root, group => 0, mode => 0755;
    }
    file{"${config_dir}/conf.d/ssl.conf":
        source => [ "puppet://$server/files/apache/centos/${fqdn}/ssl.conf", 
                    "puppet://$server/files/apache/centos/ssl.conf",
                   "puppet://$server/apache/centos/ssl.conf" 
            ],
        owner => root, group => 0, mode => 0755;
    }
    apache::vhost::file { '00_default_centos_vhost': }
}

class apache::gentoo inherits apache::base {
    $config_dir = '/etc/apache2/'

    # needs module gentoo
    gentoo::etcconfd { apache2: require => "Package[apache]", notify => "Service[apache]"} 

    Package[apache]{
        category => 'www-servers',
    } 
    File[vhosts_dir]{
        path => "$config_dir/vhosts.d/",
    }
    apache::vhost::file { '00_default_ssl_vhost': }
    apache::vhost::file { '00_default_vhost': }
    apache::config::file { 'default_vhost.include': 
        source => "apache/vhosts.d/default_vhost.include",
        destination => "$config_dir/vhosts.d/default_vhost.include",
    }
}

class apache::debian inherits apache::base {
    $config_dir = '/etc/apache2/'
    file {"vhosts_dir":
        ensure => '/etc/apache2/sites-enabled/',
    }
    File[default_apache_index] {
        path => '/var/www/index.html',
    }
}
# ubuntu is similar to debian therefor inheritng from there
class apache::ubuntu inherits apache::debian {}
class apache::openbsd inherits apache::base {
    $config_dir = '/var/www/conf/'
    File[vhosts_dir]{
        path => "$config_dir/vhosts.d/",
    }
    File[default_apache_index] {
        path => '/var/www/htdocs/index.html',
    }
}

# extended apache configs
class apache::security inherits apache {
    include apache::mod_security
}


### config things
define apache::vhost::file(
    $source = '',
    $destination = ''
){
    $vhosts_dir = $operatingsystem ? {
            centos => "$apache::centos::config_dir/vhosts.d/",
            gentoo => "$apache::gentoo::config_dir/vhosts.d/",
            debian => "$apache::debian::config_dir/vhosts.d/",
            ubuntu => "$apache::ubuntu::config_dir/vhosts.d/",
            openbsd => "$apache::openbsd::config_dir/vhosts.d/",
            default => '/etc/apache2/vhosts.d/',
    }

    $real_destination = $destination ? {
        '' => "${vhosts_dir}/${name}.conf",
        default => $destination,
    } 

    $real_source = $source ? {
        ''  => [ 
            "puppet://$server/files/apache/vhosts.d/${fqdn}/${name}.conf",
            "puppet://$server/files/apache/vhosts.d/${name}.conf", 
            "puppet://$server/apache/vhosts.d/${name}.conf" 
        ],
        default => "puppet://$server/$source",
    }

    file{"vhost_${name}.conf":
        path => $real_destination,
        source => $real_source,
        owner => root,
        group => 0,
        mode => 0644, 
        require => [ File[vhosts_dir], Package[apache] ],
        notify => Service[apache],
    }
}

define apache::config::file(
    $source = '',
    $destination = ''
){
    $real_source = $source ? {
        # get a whole bunch of possible sources if there is no specific source for that config-file
        '' => [ 
            "puppet://$server/files/apache/conf/${fqdn}/${name}",
            "puppet://$server/files/apache/conf/${name}",
            "puppet://$server/apache/conf/${name}.${operatingsystem}.${lsbdistcodename}",
            "puppet://$server/apache/conf/${name}.${operatingsystem}",
            "puppet://$server/apache/conf/${name}.Default",
            "puppet://$server/apache/conf/${name}"
        ],
        default => "puppet://$server/$source",
    }

    $real_destination = $destination ? {
        '' => $operatingsystem ? {
            centos => "$apache::centos::config_dir/${name}",
            gentoo => "$apache::gentoo::config_dir/${name}",
            debian => "$apache::debian::config_dir/${name}",
            ubuntu => "$apache::ubuntu::config_dir/${name}",
            openbsd => "$apache::openbsd::config_dir/${name}",
            default => "/etc/apache2/${name}",
        },
        default => $destination
    }

    file{"apache_${name}":
        path => $real_destination,
        source => $real_source,
        owner => root,
        group => 0,
        mode => 0644,
        require => Package[apache],
        notify => Service[apache],
    }
}

#php
class apache::php inherits apache {
    case $operatingsystem {
        debian: { include php::debian }
        centos: { include php::centos }
        ubuntu: { include php::ubuntu }
        gentoo: { include php::gentoo }
        default: { include php::base }
    }
}

class apache::status {
    case $operatingsystem {
        centos: { include apache::status::centos }
    }
    include munin::plugins::apache
}

class apache::status::centos {
    file{"/etc/httpd/conf.d/status.conf":
        source => "puppet://$server/apache/centos/status.conf",
        owner => root, group => 0, mode => 644;
    }
}