Report abuse

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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
// node.pp

node 'a.valid.hostname' {
  $admin = [ "jbooth", "haggin", "hougland" ]
  include local

  samba::client {
    "dres-kennel": 
      description => "DRES Fedora 10 Test VM";
  }

  localuser {
    ["nhoyt"]:
      ensure => present;
  }

  $faecustom = 'SNIP'

  apache::vhost {
    "test":
      host => "a.valid.hostname",
      serveralias => "a.valid.hostname",
      provider => "ip",
      https => true,
      group => "a.group",
      http_custom => "$faecustom",
      https_custom => "$faecustom";
  }

  package {
    ["Django", "ocaml", "python-psycopg2", "python-docutils", "python-lxml"]:
      ensure => present;
    ["emacs"]:
      ensure => present;
  }

  file {
    "/services/test/reports":
      seltype => "httpd_sys_script_rw_t",
      ensure => directory, require => File["/services/test"];
    "/services/test/sites":
      seltype => "httpd_sys_script_rw_t",
      ensure => directory, require => File["/services/test"];
  }

  # had to enable
  # setsebool -P httpd_can_network_connect=1

  # had to enable
  # setsebool -P httpd_can_network_connect_db=1

  # do research on
  # setsebool -P httpd_unified=1
  # and figure out if we can work around it correctly
  # or if we need to enable the above
}

// apache module
class apache {
  package {
    "httpd":
      ensure => latest;
  }
  service {
    "httpd":
      hasstatus => true, hasrestart => true,
      enable => true,
      ensure => running,
      require => Package["httpd"],
  }
  File {  require => Package["httpd"] }
  file {
    "/etc/httpd/conf.d/welcome.conf":
      ensure => absent;
  }
}

class apache::ssl inherits apache {
  package {
    "mod_ssl":
      ensure => latest,
      require => Package["httpd"];
  }
  file {
    "/etc/httpd/conf.d/ssl.conf":
      ensure => present,
      source => "puppet://$servername/apache/ssl.conf";
  }
}

define apache::vhost (
  $ensure = "present",
  $host,
  $ip = $ipaddress,
  $provider = "named",
  $http = true,
  $http_port = "80",
  $http_custom = "",
  $https = false,
  $https_port = "443",
  $https_custom = "",
  $serveradmin = "generate_in_template",
  $serveralias = "",
  $owner = "apache",
  $group = "apache",
  $dirmode = "2775",
  $filemode = "664",
  $replace = false
) {
  if ($http == false) and ($https == false) {
    fail("apache::vhost: what's the point in a vhost with no http or https access?")
  }
  if ($provider != "named") and ($provider != "ip") {
    fail("apache::vhost: provider $provider unknown!")
  }

  # Make sure we have the package and service running
  include apache

  # We'll need a service directory
  include services
  services::add {
    "$title":
      owner => $owner, group => $group, mode => $dirmode,
      lib_seltype => "httpd_sys_content_rw_t",
      ensure => $ensure;
  }

  # Include ssl if they requested https
  if ($https == true) {
    include apache::ssl
  }

  # Grant sudo privs
  include sudo
  sudo::add {
    "vhost-$title":
      who => "%$group",
      host => "ALL",
      command => "/sbin/service httpd restart",
      runas_user => "ALL",
      ensure => $ensure;
  }

  # Open those ports in the firewall
  include iptables
  if ($http == true) and !defined(Iptables::Add["apache $ipaddress $http_port"]) {
    iptables::add {
      "apache $ipaddress $http_port":
        port => $http_port;
    }
  }
  if ($https == true) and !defined(Iptables::Add["apache $ipaddress $https_port"]) {
    iptables::add {
      "apache $ipaddress $https_port":
        port => $https_port;
    }
  }

  # Handy definitions
  $configroot = "/etc/httpd/conf.d"
  $configfile = "/services/$title/vhost.conf"
  $documentroot = "/services/$title/html"
  $logroot = "/services/$title/logs"

  File {
    owner => $owner, group => $group, require => Package["httpd"],
    ensure => $ensure,
  }
  file {
    "$configroot/vhost-$title.conf":
      content => template("apache/vhost-site.conf.erb"),
      seltype => "httpd_config_t", replace => $replace,
      notify => Service["httpd"];
    "$configfile":
      require => File["/services/$title"],
      seltype => "httpd_config_t",
      ensure => $ensure ? {
        absent => "absent",
        default => "$configroot/vhost-$title.conf"
      };
    "$documentroot":
      require => File["/services/$title"], seltype => "httpd_sys_content_t",
      mode => $dirmode, ensure => $ensure ? {
        absent => "absent",
        default => "directory"
      };
    "$documentroot/index.html":
      require => File["$documentroot"], seltype => "httpd_sys_content_t",
      mode => $filemode, replace => $replace,
      content => template("apache/index.html.erb");
    "$logroot":
      require => File["/services/$title"], seltype => "httpd_log_t",
      mode => $dirmode, ensure => $ensure ? {
        absent => "absent",
        default => "directory"
      };
  }
}

// iptables module
class iptables {
  package {
    "iptables":
      ensure => present;
  }

  # Don't hasrestart => true because it returns 1 even when it passes.
  service {
    "iptables":
      hasstatus => true,
      enable => true,
      ensure => running;
  }

  concat_file {
    "/etc/sysconfig/iptables":
      mode => 0400,
      notify => Service["iptables"];
  }

  concat_file_chunk {
    "iptables-header":
      file => "/etc/sysconfig/iptables",
      priority => "00",
      content => template("iptables/iptables-header.erb");
    "iptables-footer":
      file => "/etc/sysconfig/iptables",
      priority => "99",
      content => template("iptables/iptables-footer.erb");
  }
}

define iptables::add (
  $port
) {
  include iptables
  concat_file_chunk {
    "iptables-$title":
      file => "/etc/sysconfig/iptables",
      content => template("iptables/iptables-rule.erb");
  }
}

// concat module ("custom")
class custom {
  # This just does some prep work for the defines below
  file {
    "/tmp/puppet":
      ensure => directory,
      mode => 700, owner => root, group => root;
  }
  exec {
    "cleanup /tmp/puppet":
      path => "/bin/",
      cwd => "/tmp",
      command => "rm -rf puppet",
      require => File["/tmp/puppet"];
  }
}

# This define is sick and wrong.
# It is a recursive-to-/ file { ensure => directory }
define mkdir (
  $ensure = present
) {
  $parent = template("custom/mkdir.erb")
  if !defined(Mkdir["$parent"]) and $parent != "/tmp/puppet" {
    mkdir {
      "$parent":
        ensure => $ensure;
    }
  }
  file {
    "$name":
      ensure => directory,
      owner => root, group => root, mode => 400,
      require => File["$parent"];
  }
}

define concat_file (
  $ensure = present,
  $mode = 0644, $owner = root, $group = root
) {
  include custom

  $file = "/tmp/puppet/${name}"
  $dir = "/tmp/puppet/${name}.d"
  $parent = template("custom/mkdir.erb")

  mkdir {
    "$dir":
      ensure => present;
  }

  # Make sure there's something, even if empty
  file {
    "${dir}/__nonempty__":
      owner => root, group => root, mode => 400,
      ensure => present,
      content => '',
      require => File["${dir}"];
  }

  exec {
    "concat_file_$title":
      path => ["/bin", "/usr/bin"],
      cwd => $parent,
      command => "cat $dir/* >| $file",
      require => File["${dir}/__nonempty__"];
  }

  file {
    "${name}":
      ensure => $ensure,
      owner => $owner, group => $group, mode => $mode,
      source => $file,
      require => Exec["concat_file_${name}"],
      before => Exec["cleanup /tmp/puppet"];
  }
}

define concat_file_chunk (
  $file,
  $priority = "50",
  $content = ""
) {
  file {
    "/tmp/puppet/${file}.d/${priority}-${title}":
      owner => root, group => root, mode => 400,
      content => $content,
      before => Exec["concat_file_${file}"],
      require => File["/tmp/puppet/${file}.d"];
  }
}