aboutsummaryrefslogtreecommitdiff
path: root/manifests/init.pp
blob: da844c0c8c782987617185fc9a2e2cda180c5c00 (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
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
#
# Nodo class definitions
#

import "firewall.pp"
import "firewire.pp"
import "initramfs.pp"
import "lsb.pp"
import "motd.pp"
import "sudo.pp"
import "sysctl.pp"
import "ups.pp"

class nodo {
  include lsb
  include puppetd
  include backup
  include exim
  include sudo
  include users::admin
  include motd

  # Set timezone and ntp config
  #
  # We config those here but leave class inclusion elsewhere
  # as ntp config differ from server to vserver.
  #
  $ntp_timezone = "Brazil/East"
  $ntp_pool     = "south-america.pool.ntp.org"
  $ntp_servers  = [ 'a.ntp.br', 'b.ntp.br', 'c.ntp.br' ]

  # Monkeysphere
  #
  # Currently we don't have a defined policy regarding whether
  # to publish all our node keys to public keyservers, so leave
  # automatic publishing disabled for now.
  #
  $monkeysphere_publish_key = false
  include monkeysphere

  # Apt configuration
  $backports_enabled = true
  $apt_update_method = 'cron'
  include apt

  file { "/etc/hostname":
    owner   => "root",
    group   => "root",
    mode    => 0644,
    ensure  => present,
    content => "$fqdn\n",
  }

  host { "$hostname":
    ensure => present,
    ip     => "$ipaddress",
    alias  => [ "$fqdn" ],
  }

  file { "/etc/rc.local":
    source  => "puppet://$server/modules/nodo/etc/rc.local",
    owner   => "root",
    group   => "root",
    mode    => 0755,
    ensure  => present,
  }
}

class nodo::server inherits nodo {
  include syslog-ng
  include ntpdate
  include firewall
  include vserver::host
  include initramfs
  include firewire
  include sysctl
  include ups

  # DNS resolver
  $resolvconf_domain = "$domain"
  $resolvconf_search = "$fqdn"
  include resolvconf

  # SSH Server
  #
  # We need to restrict listen address so multiple instances
  # can live together in the same physical host.
  #
  $sshd_listen_address = [ "$ipaddress" ]
  $sshd_password_authentication = "yes"
  include sshd

  # Munin
  #$munin_port = "4901"
  #include munin::client

  backupninja::sys { "sys":
    ensure => present,
  }

  # fstab
  file { "/etc/fstab":
    source  => "puppet://$server/modules/nodo/etc/fstab",
    owner   => "root",
    group   => "root",
    mode    => 0644,
    ensure  => present,
  }

  # crypttab
  file { "/etc/crypttab":
    source  => "puppet://$server/modules/nodo/etc/crypttab",
    owner   => "root",
    group   => "root",
    mode    => 0644,
    ensure  => present,
  }
}

class nodo::vserver inherits nodo {
  $sshd_password_authentication = "yes"
  $sshd_internal_ip             = "yes"
  include sshd
  include timezone
  include syslog-ng::vserver

  backupninja::sys { "sys":
    ensure     => present,
    partitions => false,
    hardware   => false,
    dosfdisk   => false,
    dohwinfo   => false,
  }

  define munin($type, $id) {
    # Use one port for each node
    $munin_port = "49$id"
    case $type {
      'host': {
        include munin::host
        include munin::client
      }
      'client': {
        include munin::client
      }
    }
  }

  # Apply the munin configuration for this host
  #Nodo::vserver::munin <| tag == $name |>

  # Define a vserver instance
  define instance($context, $ensure = 'running', $proxy = false, $puppetmaster = false, $gitd = false, $munin = 'client') {

    # set instance id
    if $context < 9 {
      $id = "0$context"
    } else {
      $id = $context
    }

    vserver { $name:
      ensure    => $ensure,
      context   => "$context",
      mark      => 'default',
      distro    => 'lenny',
      interface => "eth0:192.168.0.$context/24",
      hostname  => "$name.$domain",
    }

    # Some nodes need a lot of space at /tmp otherwise some admin
    # tasks like backups might not run.
    file { "/etc/vservers/${name}/fstab":
      source  => "puppet://$server/modules/nodo/etc/fstab-vserver",
      owner   => "root",
      group   => "root",
      mode    => 0644,
      ensure  => present,
      notify  => Exec["vs_restart_${name}"],
      require => Exec["vs_create_${name}"],
    }

    # Create a munin virtual resource to be realized in the node
    #@nodo::vserver::munin {
    #  type => $munin,
    #  id   => $id,
    #  tag  => $name,
    #}

    # Apply firewall rules just for running vservers
    case $ensure {
      'running': {

        shorewall::rule { "ssh-$context":
          action          => 'DNAT',
          source          => 'net',
          destination     => "vm:192.168.0.$context:22",
          proto           => 'tcp',
          destinationport => "22$id",
          ratelimit       => '-',
          order           => "2$id",
        }

        if $proxy {
          shorewall::rule { 'http-route':
            action          => 'DNAT',
            source          => 'net',
            destination     => "vm:192.168.0.$context:80",
            proto           => 'tcp',
            destinationport => '80',
            ratelimit       => '-',
            order           => '300',
          }

          shorewall::rule { 'https-route':
            action          => 'DNAT',
            source          => 'net',
            destination     => "vm:192.168.0.$context:443",
            proto           => 'tcp',
            destinationport => '443',
            ratelimit       => '-',
            order           => '301',
          }
        }

        if $puppetmaster {
          shorewall::rule { 'puppetmaster-1':
            action          => 'DNAT',
            source          => 'net',
            destination     => "fw:192.168.0.$context:8140",
            proto           => 'tcp',
            destinationport => '8140',
            ratelimit       => '-',
            order           => '302',
          }

          shorewall::rule { 'puppetmaster-2':
            action          => 'DNAT',
            source          => 'net',
            destination     => "fw:192.168.0.$context:8140",
            proto           => 'udp',
            destinationport => '8140',
            ratelimit       => '-',
            order           => '303',
          }

          shorewall::rule { 'puppetmaster-3':
            action          => 'DNAT',
            source          => '$FW',
            destination     => "fw:192.168.0.$context:8140",
            proto           => 'tcp',
            destinationport => '8140',
            ratelimit       => '-',
            order           => '304',
          }

          shorewall::rule { 'puppetmaster-4':
            action          => 'DNAT',
            source          => '$FW',
            destination     => "fw:192.168.0.$context:8140",
            proto           => 'udp',
            destinationport => '8140',
            ratelimit       => '-',
            order           => '305',
          }
        }

        if $gitd {
          shorewall::rule { 'git-daemon-1':
            action          => 'DNAT',
            source          => 'net',
            destination     => "fw:192.168.0.$context:9418",
            proto           => 'tcp',
            destinationport => '9418',
            ratelimit       => '-',
            order           => '306',
          }

          shorewall::rule { 'git-daemon-2':
            action          => 'DNAT',
            source          => '$FW',
            destination     => "vm:192.168.0.$context:9418",
            proto           => 'tcp',
            destinationport => '9418',
            ratelimit       => '-',
            order           => '307',
          }
        }
      }
    }
  }
}

class nodo::web inherits nodo::vserver {
  include git-daemon
  include websites
  include mysql::server
  include users::virtual

  backupninja::svn { "svn":
    src => "/var/svn",
  }

  backupninja::mysql { "all_databases":
  	backupdir => '/var/backups/mysql',
  	compress  => true,
  	sqldump   => true,
  }
}

class nodo::proxy inherits nodo::vserver {
  # TODO: openssl?
  include nginx
}