summaryrefslogtreecommitdiff
path: root/manifests/init.pp
blob: db77b1434a11f03c4cfa648fedad40f316fedb67 (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
#
# apache module
#
# Copyright 2008, admin(at)immerda.ch
# Copyright 2008, Puzzle ITC GmbH
# Marcel Härry haerry+puppet(at)puzzle.ch
# Simon Josi josi+puppet(at)puzzle.ch
#
# This program is free software; you can redistribute 
# it and/or modify it under the terms of the GNU 
# General Public License version 3 as published by 
# the Free Software Foundation.
#

import "defines.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 }
    }
    if $selinux {
        include apache::selinux
    }
    if $use_munin {
        include apache::status
    }
}

class apache::base {
    file{'vhosts_dir':
        path => '/etc/apache2/vhosts.d/',
        ensure => directory,
        owner => root, group => 0, mode => 0755;
    }
    file{'modules_dir':
        path => '/etc/apache2/modules.d/',
        ensure => directory,
        owner => root, group => 0, mode => 0755;
    }
    service { apache:
        name => 'apache2',
        enable => true,
        ensure => running,
    }
    file { 'default_apache_index':
        path => '/var/www/localhost/htdocs/index.html',
        ensure => file,
        content => template('apache/default/default_index.erb'),
        owner => root, group => 0, mode => 0644;
    }
}

class apache::package inherits apache::base {
    package { 'apache':
        name => 'apache',
        ensure => present,
    }
    File['vhosts_dir']{
        require => Package[apache],
    }
    Service['apache']{
        require => Package[apache],
    }
    File['default_apache_index']{
        require => Package[apache],
    }
    File['modules_dir']{
        require => Package[apache],
    }
}


### distribution specific classes

### centos
class apache::centos inherits apache::package {
    $config_dir = '/etc/httpd/'

    Package[apache]{
        name => 'httpd',
    } 
    Service[apache]{
        name => 'httpd',
    }
    File[vhosts_dir]{
        path => "$config_dir/vhosts.d/",
    }
    File[modules_dir]{
        path => "$config_dir/modules.d/",
    }
    File[default_apache_index]{
        path => '/var/www/html/index.html',
    }
    apache::config::file{ 'welcome.conf': }
    apache::config::file{ 'defaults.inc': }
    apache::config::file{ 'vhosts.conf': }
    apache::vhost::file { '0-default': }
}

### gentoo
class apache::gentoo inherits apache::package {
    $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/",
    }
    File[modules_dir]{
        path => "$config_dir/modules.d/",
    }
    apache::gentoo::module { '00_default_settings': }
    apache::gentoo::module { '00_error_documents': }

    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",
    }
    
    # set the default for the ServerName
    file{"${config_dir}/modules.d/00_default_settings_ServerName.conf":
        content => template('apache/modules_dir_00_default_settings_ServerName.conf.erb'),
        require => Package[apache],
        owner => root, group => 0, mode => 0644;
    }
}

### debian
class apache::debian inherits apache::package {
    $config_dir = '/etc/apache2/'

    file {"$vhosts_dir":
        ensure => '/etc/apache2/sites-enabled/',
    }
    File[default_apache_index] {
        path => '/var/www/index.html',
    }

}

### ubuntu: similar to debian therefor inheritng from there
class apache::ubuntu inherits apache::debian {}

### openbsd
class apache::openbsd inherits apache::base {
    $config_dir = '/var/www/conf/'

    File[vhosts_dir]{
        path => "$config_dir/vhosts.d/",
    }
    File[modules_dir]{
        path => "$config_dir/modules.d/",
    }
    File[default_apache_index] {
        path => '/var/www/htdocs/index.html',
    }
}