/
init.pp
171 lines (151 loc) · 4.56 KB
/
init.pp
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
# @summary Configures an Apache server
#
# Ensures that the appropriate files are in the appropriate places and can
# optionally rsync the `/var/www/html` content.
#
# Ideally, we will move over to the Puppet Labs apache module in the future but
# it's going to be quite a bit of work to port all of our code.
#
# @NOTE: If a parameter is not listed here then it is part of the standard
# Apache configuration set and the stock Apache documentation should be
# referenced.
#
# @param data_dir
# The location where apache web data should be stored. Set to /srv/www for
# legacy reasons.
#
# @param rsync_web_root
# Whether or not to rsync over the web root.
#
# @param ssl
# Whether or not to enable SSL. You will need to set the Hiera
# variables for apache::ssl appropriately for your needs.
#
# @author Trevor Vaughan <tvaughan@onyxpoint.com>
#
class simp_apache (
Stdlib::AbsolutePath $data_dir = '/var/www',
Boolean $ssl = true,
String $rsync_source = "apache_${::environment}_${facts['os']['name']}/www",
Simplib::Host $rsync_server = simplib::lookup('simp_options::rsync::server', { 'default_value' => '127.0.0.1' }),
Integer $rsync_timeout = simplib::lookup('simp_options::rsync::timeout', { 'default_value' => 2 }),
Boolean $rsync_web_root = true
) {
simplib::assert_metadata($module_name)
include 'simp_apache::install'
include 'simp_apache::conf'
include 'simp_apache::service'
if $ssl {
include 'simp_apache::ssl'
Class['simp_apache::install'] -> Class['simp_apache::ssl']
}
Class['simp_apache::install'] -> Class['simp_apache']
Class['simp_apache::install'] -> Class['simp_apache::conf']
Class['simp_apache::install'] ~> Class['simp_apache::service']
Class['simp_apache::conf'] ~> Class['simp_apache::service']
if $facts['os']['name'] in ['RedHat','CentOS','OracleLinux'] {
if (versioncmp($facts['os']['release']['major'],'7') >= 0) {
$apache_homedir = '/usr/share/httpd'
}
else {
$apache_homedir = '/var/www'
}
}
else {
$apache_homedir = '/var/www'
}
$_modules_target = $facts['hardwaremodel'] ? {
'x86_64' => '/usr/lib64/httpd/modules',
default => '/usr/lib/httpd/modules'
}
file { $data_dir:
ensure => 'directory',
owner => 'root',
group => 'apache',
mode => '0640'
}
file { '/etc/httpd/conf/magic':
owner => 'root',
group => 'apache',
mode => '0640',
source => "puppet:///modules/${module_name}/magic",
notify => Class['simp_apache::service']
}
file { '/etc/httpd/conf.d/welcome.conf': ensure => 'absent' }
file { '/etc/mime.types':
owner => 'root',
group => 'root',
mode => '0644',
notify => Class['simp_apache::service']
}
file { '/etc/httpd/logs':
ensure => 'symlink',
target => '/var/log/httpd',
force => true
}
file { '/etc/httpd/modules':
ensure => 'symlink',
target => $_modules_target,
force => true
}
file { '/etc/httpd/run':
ensure => 'symlink',
target => '/var/run/httpd',
force => true,
}
file { '/var/log/httpd':
ensure => 'directory',
owner => 'root',
group => 'root',
mode => '0700'
}
file { 'httpd_modules':
ensure => 'directory',
path => $_modules_target,
owner => 'root',
group => 'root',
mode => '0755',
notify => Class['simp_apache::service']
}
group { 'apache':
ensure => 'present',
allowdupe => false,
gid => '48'
}
if $rsync_web_root {
include 'rsync'
# Rsync the /var/www space from the rsync server.
# Add anything here you want to go to every web server.
$_downcase_os_name = downcase($facts['os']['name'])
rsync { 'site':
user => "apache_rsync_${::environment}_${_downcase_os_name}",
password => simplib::passgen("apache_rsync_${::environment}_${_downcase_os_name}"),
source => $rsync_source,
target => '/var',
server => $rsync_server,
timeout => $rsync_timeout,
delete => false
}
}
if $::selinux_current_mode and $::selinux_current_mode != 'disabled' {
selboolean { [
'httpd_verify_dns',
'allow_ypbind',
'allow_httpd_mod_auth_pam',
'httpd_can_network_connect'
]:
persistent => true,
value => 'on'
}
}
user { 'apache':
ensure => 'present',
allowdupe => false,
gid => '48',
home => $apache_homedir,
membership => 'minimum',
shell => '/sbin/nologin',
uid => '48',
require => Group['apache']
}
}