1 |
class apache { |
2 |
|
3 |
class base { |
4 |
$php_date_timezone = "UTC" |
5 |
|
6 |
# number of time the log file are rotated before being removed |
7 |
$httpdlogs_rotate = "24" |
8 |
|
9 |
$apache_user = 'apache' |
10 |
$apache_group = 'apache' |
11 |
|
12 |
package { "apache-mpm-prefork": |
13 |
alias => apache, |
14 |
ensure => installed |
15 |
} |
16 |
|
17 |
package { "apache-conf": |
18 |
ensure => installed, |
19 |
} |
20 |
|
21 |
service { httpd: |
22 |
alias => apache, |
23 |
ensure => running, |
24 |
subscribe => [ Package['apache-mpm-prefork'] ], |
25 |
} |
26 |
|
27 |
file { "customization.conf": |
28 |
ensure => present, |
29 |
path => "/etc/httpd/conf.d/customization.conf", |
30 |
content => template("apache/customization.conf"), |
31 |
require => Package["apache-conf"], |
32 |
notify => Service["apache"], |
33 |
owner => root, |
34 |
group => root, |
35 |
mode => 644, |
36 |
} |
37 |
|
38 |
file { "00_default_vhosts.conf": |
39 |
path => "/etc/httpd/conf/vhosts.d/00_default_vhosts.conf", |
40 |
ensure => "present", |
41 |
owner => root, |
42 |
group => root, |
43 |
mode => 644, |
44 |
notify => Service['apache'], |
45 |
require => Package["apache-conf"], |
46 |
content => template("apache/00_default_vhosts.conf") |
47 |
} |
48 |
|
49 |
file { "/etc/logrotate.d/httpd": |
50 |
ensure => "present", |
51 |
owner => root, |
52 |
group => root, |
53 |
mode => 644, |
54 |
content => template("apache/logrotate") |
55 |
} |
56 |
|
57 |
} |
58 |
|
59 |
class mod_php inherits base { |
60 |
package { "apache-mod_php": |
61 |
ensure => installed |
62 |
} |
63 |
|
64 |
file { "/etc/httpd/conf.d/mod_php.conf": |
65 |
ensure => present, |
66 |
owner => root, |
67 |
group => root, |
68 |
mode => 644, |
69 |
require => Package['apache-conf'], |
70 |
content => template('apache/mod_php.conf'), |
71 |
notify => Service['apache'], |
72 |
} |
73 |
} |
74 |
|
75 |
class mod_perl inherits base { |
76 |
package { "apache-mod_perl": |
77 |
ensure => installed |
78 |
} |
79 |
} |
80 |
|
81 |
class mod_fcgid inherits base { |
82 |
package { "apache-mod_fcgid": |
83 |
ensure => installed |
84 |
} |
85 |
} |
86 |
|
87 |
class mod_fastcgi inherits base { |
88 |
package { "apache-mod_fastcgi": |
89 |
ensure => installed |
90 |
} |
91 |
} |
92 |
|
93 |
class mod_ssl inherits base { |
94 |
file { "/etc/ssl/apache/": |
95 |
ensure => directory |
96 |
} |
97 |
|
98 |
package { "apache-mod_ssl": |
99 |
ensure => installed |
100 |
} |
101 |
|
102 |
file { "01_default_ssl_vhost.conf": |
103 |
path => '/etc/httpd/conf/vhosts.d/01_default_ssl_vhost.conf', |
104 |
ensure => "present", |
105 |
owner => root, |
106 |
group => root, |
107 |
mode => 644, |
108 |
notify => Service['apache'], |
109 |
require => Package["apache-conf"], |
110 |
content => template("apache/01_default_ssl_vhost.conf") |
111 |
} |
112 |
|
113 |
file { "ssl.conf": |
114 |
ensure => present, |
115 |
path => "/etc/httpd/conf.d/ssl.conf", |
116 |
content => template("apache/ssl.conf"), |
117 |
require => Package["apache-conf"], |
118 |
notify => Service["apache"], |
119 |
owner => root, |
120 |
group => root, |
121 |
mode => 644, |
122 |
} |
123 |
} |
124 |
|
125 |
class mod_wsgi inherits base { |
126 |
package { "apache-mod_wsgi": |
127 |
ensure => installed |
128 |
} |
129 |
|
130 |
file { "/usr/local/lib/wsgi": |
131 |
ensure => directory, |
132 |
owner => root, |
133 |
group => root, |
134 |
mode => 644, |
135 |
} |
136 |
|
137 |
file { "/etc/httpd/conf.d/mod_wsgi.conf": |
138 |
ensure => present, |
139 |
owner => root, |
140 |
group => root, |
141 |
mode => 644, |
142 |
require => Package['apache-conf'], |
143 |
content => template('apache/mod_wsgi.conf'), |
144 |
notify => Service['apache'], |
145 |
} |
146 |
|
147 |
} |
148 |
|
149 |
class mod_proxy inherits base { |
150 |
package { "apache-mod_proxy": |
151 |
ensure => installed |
152 |
} |
153 |
} |
154 |
|
155 |
class mod_public_html inherits base { |
156 |
package { "apache-mod_public_html": |
157 |
ensure => installed |
158 |
} |
159 |
} |
160 |
|
161 |
class mod_deflate inherits base { |
162 |
package { "apache-mod_deflate": |
163 |
ensure => installed |
164 |
} |
165 |
} |
166 |
|
167 |
class mod_geoip inherits base { |
168 |
package { "apache-mod_geoip": |
169 |
ensure => installed |
170 |
} |
171 |
} |
172 |
|
173 |
define vhost_base($content = '', |
174 |
$location = '/dev/null', |
175 |
$use_ssl = false, |
176 |
$vhost = false, |
177 |
$aliases = {}, |
178 |
$server_aliases = [], |
179 |
$access_logfile = false, |
180 |
$error_logfile = false, |
181 |
$options = [], |
182 |
$enable_public_html = false) { |
183 |
include apache::base |
184 |
$httpd_logdir = "/var/log/httpd" |
185 |
if ! $vhost { |
186 |
$real_vhost = $name |
187 |
} else { |
188 |
$real_vhost = $vhost |
189 |
} |
190 |
|
191 |
if ! $access_logfile { |
192 |
$real_access_logfile = "$httpd_logdir/${real_vhost}-access_log" |
193 |
} else { |
194 |
$real_access_logfile = $access_logfile |
195 |
} |
196 |
if ! $error_logfile { |
197 |
$real_error_logfile = "$httpd_logdir/${real_vhost}-error_log" |
198 |
} else { |
199 |
$real_error_logfile = $error_logfile |
200 |
} |
201 |
|
202 |
if $use_ssl { |
203 |
include apache::mod_ssl |
204 |
if $wildcard_sslcert != 'true' { |
205 |
openssl::self_signed_cert{ "$real_vhost": |
206 |
directory => "/etc/ssl/apache/", |
207 |
before => File["$filename"], |
208 |
} |
209 |
} |
210 |
} |
211 |
|
212 |
if $enable_public_html { |
213 |
include apache::mod_public_html |
214 |
} |
215 |
|
216 |
$filename = "$name.conf" |
217 |
file { "$filename": |
218 |
path => "/etc/httpd/conf/vhosts.d/$filename", |
219 |
ensure => "present", |
220 |
owner => root, |
221 |
group => root, |
222 |
mode => 644, |
223 |
notify => Service['apache'], |
224 |
require => Package['apache-conf'], |
225 |
content => template("apache/vhost_base.conf") |
226 |
} |
227 |
} |
228 |
|
229 |
define vhost_redirect_ssl() { |
230 |
vhost_base { "redirect_ssl_$name": |
231 |
vhost => $name, |
232 |
content => template("apache/vhost_ssl_redirect.conf") |
233 |
} |
234 |
} |
235 |
|
236 |
define vhost_catalyst_app($script, $location = '', $process = 4, $use_ssl = false, $vhost = false) { |
237 |
|
238 |
include apache::mod_fastcgi |
239 |
vhost_base { $name: |
240 |
vhost => $vhost, |
241 |
use_ssl => $use_ssl, |
242 |
content => template("apache/vhost_catalyst_app.conf") |
243 |
} |
244 |
} |
245 |
|
246 |
define vhost_django_app($module = false, $module_path = false, $use_ssl = false, $aliases= {}) { |
247 |
include apache::mod_wsgi |
248 |
vhost_base { $name: |
249 |
use_ssl => $use_ssl, |
250 |
content => template("apache/vhost_django_app.conf"), |
251 |
aliases => $aliases, |
252 |
} |
253 |
|
254 |
# module is a ruby reserved keyword, cannot be used in templates |
255 |
$django_module = $module |
256 |
file { "$name.wsgi": |
257 |
path => "/usr/local/lib/wsgi/$name.wsgi", |
258 |
ensure => "present", |
259 |
owner => root, |
260 |
group => root, |
261 |
mode => 755, |
262 |
notify => Service['apache'], |
263 |
content => template("apache/django.wsgi") |
264 |
} |
265 |
} |
266 |
|
267 |
define vhost_wsgi($wsgi_path, $aliases = {}, $server_aliases = []) { |
268 |
include apache::mod_wsgi |
269 |
vhost_base { $name: |
270 |
aliases => $aliases, |
271 |
server_aliases => $server_aliases, |
272 |
content => template("apache/vhost_wsgi.conf") |
273 |
} |
274 |
} |
275 |
|
276 |
define vhost_other_app($vhost_file) { |
277 |
include apache::base |
278 |
file { "$name.conf": |
279 |
path => "/etc/httpd/conf/vhosts.d/$name.conf", |
280 |
ensure => "present", |
281 |
owner => root, |
282 |
group => root, |
283 |
mode => 644, |
284 |
notify => Service['apache'], |
285 |
require => Package['apache-conf'], |
286 |
content => template($vhost_file) |
287 |
} |
288 |
} |
289 |
|
290 |
define vhost_simple($location) { |
291 |
include apache::base |
292 |
vhost_base { $name: |
293 |
location => $location, |
294 |
} |
295 |
} |
296 |
|
297 |
define vhost_redirect($url, |
298 |
$vhost = false, |
299 |
$use_ssl = false) { |
300 |
include apache::base |
301 |
vhost_base { $name: |
302 |
use_ssl => $use_ssl, |
303 |
vhost => $vhost, |
304 |
content => template("apache/vhost_redirect.conf"), |
305 |
} |
306 |
} |
307 |
|
308 |
define vhost_reverse_proxy($url, |
309 |
$vhost = false, |
310 |
$use_ssl = false) { |
311 |
include apache::mod_proxy |
312 |
vhost_base { $name: |
313 |
use_ssl => $use_ssl, |
314 |
vhost => $vhost, |
315 |
content => template("apache/vhost_reverse_proxy.conf") |
316 |
} |
317 |
} |
318 |
|
319 |
define webapp_other($webapp_file) { |
320 |
include apache::base |
321 |
$webappname = $name |
322 |
file { "webapp_$name.conf": |
323 |
path => "/etc/httpd/conf/webapps.d/$webappname.conf", |
324 |
ensure => "present", |
325 |
owner => root, |
326 |
group => root, |
327 |
mode => 644, |
328 |
notify => Service['apache'], |
329 |
require => Package['apache-conf'], |
330 |
content => template($webapp_file) |
331 |
} |
332 |
} |
333 |
} |