Set /etc/environment and /etc/default/locale with puppet instead of in new-machine...
[mirror/dsa-puppet.git] / modules / debian_org / manifests / init.pp
1 # == Class: debian_org
2 #
3 # Stuff common to all debian.org servers
4 #
5 class debian_org {
6         include debian_org::apt
7
8         if $systemd {
9                 include systemd
10                 $servicefiles = 'present'
11         } else {
12                 $servicefiles = 'absent'
13         }
14
15         # the virtual facter needs virt-what on jessie to work
16         if versioncmp($::lsbmajdistrelease, '9') < 0 {
17                 package { 'virt-what': ensure => installed }
18         } else {
19                 package { 'virt-what': ensure => purged }
20         }
21
22         $samhain_recipients = hiera('samhain_recipients')
23         $root_mail_alias = hiera('root_mail_alias')
24
25         package { [
26                         'klogd',
27                         'sysklogd',
28                         'rsyslog',
29                         'os-prober',
30                         'apt-listchanges',
31                         'mlocate',
32                 ]:
33                 ensure => purged,
34         }
35         package { [
36                         'debian.org',
37                         'debian.org-recommended',
38                         'dsa-munin-plugins',
39                         'userdir-ldap',
40                 ]:
41                 ensure => installed,
42                 tag    => extra_repo,
43         }
44         file { '/etc/ssh/ssh_known_hosts':
45                 ensure  => present,
46                 replace => false,
47                 mode    => '0644',
48                 source  => 'puppet:///modules/debian_org/basic-ssh_known_hosts'
49         }
50
51         if versioncmp($::lsbmajdistrelease, '8') >= 0 {
52                 $rubyfs_package = 'ruby-filesystem'
53         } else {
54                 $rubyfs_package = 'libfilesystem-ruby1.9'
55         }
56         package { [
57                         'apt-utils',
58                         'bash-completion',
59                         'dnsutils',
60                         'less',
61                         'lsb-release',
62                         $rubyfs_package,
63                         'mtr-tiny',
64                         'nload',
65                         'pciutils',
66                         'lldpd',
67                 ]:
68                 ensure => installed,
69         }
70
71         munin::check { [
72                         'cpu',
73                         'entropy',
74                         'forks',
75                         'interrupts',
76                         'iostat',
77                         'irqstats',
78                         'load',
79                         'memory',
80                         'open_files',
81                         'open_inodes',
82                         'processes',
83                         'swap',
84                         'uptime',
85                         'vmstat',
86                 ]:
87         }
88
89         if getfromhash($site::nodeinfo, 'broken-rtc') {
90                 package { 'fake-hwclock':
91                         ensure => installed,
92                         tag    => extra_repo,
93                 }
94         }
95
96         package { 'molly-guard':
97                 ensure => installed,
98         }
99         file { '/etc/molly-guard/run.d/10-check-kvm':
100                 mode    => '0755',
101                 source  => 'puppet:///modules/debian_org/molly-guard/10-check-kvm',
102                 require => Package['molly-guard'],
103         }
104         file { '/etc/molly-guard/run.d/15-acquire-reboot-lock':
105                 mode    => '0755',
106                 source  => 'puppet:///modules/debian_org/molly-guard/15-acquire-reboot-lock',
107                 require => Package['molly-guard'],
108         }
109
110         augeas { 'inittab_replicate':
111                 context => '/files/etc/inittab',
112                 changes => [
113                         'set ud/runlevels 2345',
114                         'set ud/action respawn',
115                         'set ud/process "/usr/bin/ud-replicated -d"',
116                 ],
117                 notify  => Exec['init q'],
118         }
119
120
121         file { '/etc/facter':
122                 ensure  => directory,
123                 purge   => true,
124                 force   => true,
125                 recurse => true,
126                 source  => 'puppet:///files/empty/',
127         }
128         file { '/etc/facter/facts.d':
129                 ensure => directory,
130         }
131         file { '/etc/facter/facts.d/debian_facts.yaml':
132                 content => template('debian_org/debian_facts.yaml.erb')
133         }
134         file { '/etc/timezone':
135                 source => 'puppet:///modules/debian_org/timezone',
136                 notify => Exec['dpkg-reconfigure tzdata -pcritical -fnoninteractive'],
137         }
138         if $::hostname == handel {
139                 include puppetmaster::db
140                 $dbpassword = $puppetmaster::db::password
141         }
142         file { '/etc/puppet/puppet.conf':
143                 content => template('debian_org/puppet.conf.erb'),
144                 mode => '0440',
145                 group => 'puppet',
146         }
147         file { '/etc/default/puppet':
148                 source => 'puppet:///modules/debian_org/puppet.default',
149         }
150         file { '/etc/systemd':
151                 ensure  => directory,
152                 mode => '0755',
153         }
154         file { '/etc/systemd/system':
155                 ensure  => directory,
156                 mode => '0755',
157         }
158         file { '/etc/systemd/system/ud-replicated.service':
159                 ensure => $servicefiles,
160                 source => 'puppet:///modules/debian_org/ud-replicated.service',
161                 notify => Exec['systemctl daemon-reload'],
162         }
163         if $systemd {
164                 file { '/etc/systemd/system/multi-user.target.wants/ud-replicated.service':
165                         ensure => 'link',
166                         target => '../ud-replicated.service',
167                         notify => Exec['systemctl daemon-reload'],
168                 }
169         }
170         file { '/etc/systemd/system/puppet.service':
171                 ensure => 'link',
172                 target => '/dev/null',
173                 notify => Exec['systemctl daemon-reload'],
174         }
175         file { '/etc/systemd/system/proc-sys-fs-binfmt_misc.automount':
176                 ensure => 'link',
177                 target => '/dev/null',
178                 notify => Exec['systemctl daemon-reload'],
179         }
180
181         file { '/etc/cron.d/dsa-puppet-stuff':
182                 content => template('debian_org/dsa-puppet-stuff.cron.erb'),
183                 require => Package['debian.org'],
184         }
185         file { '/etc/ldap/ldap.conf':
186                 require => Package['debian.org'],
187                 content  => template('debian_org/ldap.conf.erb'),
188         }
189         file { '/etc/pam.d/common-session':
190                 require => Package['debian.org'],
191                 content => template('debian_org/pam.common-session.erb'),
192         }
193         file { '/etc/pam.d/common-session-noninteractive':
194                 require => Package['debian.org'],
195                 content => template('debian_org/pam.common-session-noninteractive.erb'),
196         }
197         file { '/etc/rc.local':
198                 mode   => '0755',
199                 content => template('debian_org/rc.local.erb'),
200                 notify => Exec['service rc.local restart'],
201         }
202         file { '/etc/dsa':
203                 ensure => directory,
204                 mode   => '0755',
205         }
206         file { '/etc/dsa/cron.ignore.dsa-puppet-stuff':
207                 source  => 'puppet:///modules/debian_org/dsa-puppet-stuff.cron.ignore',
208                 require => Package['debian.org']
209         }
210         file { '/etc/nsswitch.conf':
211                 mode   => '0755',
212                 source => 'puppet:///modules/debian_org/nsswitch.conf',
213         }
214
215         file { '/etc/profile.d/timeout.sh':
216                 mode   => '0555',
217                 source => 'puppet:///modules/debian_org/etc.profile.d/timeout.sh',
218         }
219         file { '/etc/zsh':
220                 ensure => directory,
221         }
222         file { '/etc/zsh/zprofile':
223                 mode   => '0444',
224                 source => 'puppet:///modules/debian_org/etc.zsh/zprofile',
225         }
226         file { '/etc/environment':
227                 content => "",
228                 mode => '0440',
229         }
230         file { '/etc/default/locale':
231                 content => "",
232                 mode => '0440',
233         }
234
235         # set mmap_min_addr to 4096 to mitigate
236         # Linux NULL-pointer dereference exploits
237         site::sysctl { 'mmap_min_addr':
238                 ensure => absent
239         }
240         site::sysctl { 'perf_event_paranoid':
241                 key   => 'kernel.perf_event_paranoid',
242                 value => '2',
243         }
244         site::sysctl { 'puppet-vfs_cache_pressure':
245                 key   => 'vm.vfs_cache_pressure',
246                 value => '10',
247         }
248         site::alternative { 'editor':
249                 linkto => '/usr/bin/vim.basic',
250         }
251         site::alternative { 'view':
252                 linkto => '/usr/bin/vim.basic',
253         }
254         mailalias { 'samhain-reports':
255                 ensure    => present,
256                 recipient => $samhain_recipients,
257                 require   => Package['debian.org']
258         }
259         mailalias { 'root':
260                 ensure    => present,
261                 recipient => $root_mail_alias,
262                 require   => Package['debian.org']
263         }
264
265         file { '/usr/local/bin/check_for_updates':
266                 source => 'puppet:///modules/debian_org/check_for_updates',
267                 mode   => '0755',
268                 owner  => root,
269                 group  => root,
270         }
271         file { '/usr/local/bin/dsa-is-shutdown-scheduled':
272                 source  => 'puppet:///modules/debian_org/dsa-is-shutdown-scheduled',
273                 mode    => '0555',
274         }
275
276         exec { 'dpkg-reconfigure tzdata -pcritical -fnoninteractive':
277                 path        => '/usr/bin:/usr/sbin:/bin:/sbin',
278                 refreshonly => true
279         }
280         exec { 'service puppetmaster restart':
281                 refreshonly => true
282         }
283         exec { 'service rc.local restart':
284                 refreshonly => true
285         }
286         exec { 'init q':
287                 refreshonly => true
288         }
289
290         exec { 'systemctl daemon-reload':
291                 refreshonly => true,
292                 onlyif  => "test -x /bin/systemctl"
293         }
294
295         exec { 'systemd-tmpfiles --create --exclude-prefix=/dev':
296                 refreshonly => true,
297                 onlyif  => "test -x /bin/systemd-tmpfiles"
298         }
299
300         tidy { '/var/lib/puppet/clientbucket/':
301                 age      => '2w',
302                 recurse  => 9,
303                 type     => ctime,
304                 matches  => [ 'paths', 'contents' ],
305                 schedule => weekly
306         }
307
308         file { '/root/.bashrc':
309                 source => 'puppet:///modules/debian_org/root-dotfiles/bashrc',
310         }
311         file { '/root/.profile':
312                 source => 'puppet:///modules/debian_org/root-dotfiles/profile',
313         }
314         file { '/root/.selected_editor':
315                 source => 'puppet:///modules/debian_org/root-dotfiles/selected_editor',
316         }
317         file { '/root/.screenrc':
318                 source => 'puppet:///modules/debian_org/root-dotfiles/screenrc',
319         }
320         file { '/root/.tmux.conf':
321                 source => 'puppet:///modules/debian_org/root-dotfiles/tmux.conf',
322         }
323         file { '/root/.vimrc':
324                 source => 'puppet:///modules/debian_org/root-dotfiles/vimrc',
325         }
326
327         if versioncmp($::lsbmajdistrelease, '9') >= 0 { # older puppets do facts as strings.
328                 if $::processorcount > 1 {
329                         package { 'irqbalance': ensure => installed }
330                 }
331         }
332 }