grub: don't hardcode the list of hosts with nopat
[mirror/dsa-puppet.git] / modules / grub / manifests / init.pp
1 class grub {
2         $grub_do_ifnames = ($::kernel == 'Linux' and $::is_virtual and $::virtual == 'kvm')
3
4         if ($::kernel == 'Linux' and $::is_virtual and $::virtual == 'kvm') {
5                 $grub_manage = true
6                 $grub_do_kernel_serial = true
7                 $grub_do_grub_serial = true
8         } elsif $::hostname in [ubc-enc2bl01,ubc-enc2bl02,ubc-enc2bl09,ubc-enc2bl10,casulana,mirror-anu,sallinen,storace,mirror-accumu,bm-bl1,bm-bl2,bm-bl3,bm-bl4,bm-bl5,bm-bl6,bm-bl7,bm-bl8,bm-bl9,bm-bl10,bm-bl11,bm-bl12,bm-bl13,bm-bl14] {
9                 $grub_manage = true
10                 $grub_do_kernel_serial = true
11                 $grub_do_grub_serial = true
12         } elsif $::hostname in [mirror-skroutz,aagaard,acker,arm-arm-01,fasolo] {
13                 $grub_manage = true
14                 $grub_do_kernel_serial = true
15                 $grub_do_grub_serial = true
16         } elsif $::hostname in [arm-arm-03] {
17                 $grub_manage = true
18                 $grub_do_kernel_serial = true
19                 $grub_do_grub_serial = false
20         } elsif $::hostname in [villa] {
21                 $grub_manage = true
22                 $grub_do_kernel_serial = false
23                 $grub_do_grub_serial = false
24         } else {
25                 $grub_manage = false
26         }
27
28         # hp-health requires nopat on linux 4.9
29         $grub_do_nopat = ($::systemproductname =~ /^ProLiant/ and versioncmp($::kernelversion, '4.9') >= 0)
30         $grub_do_extra = $::hostname in [fasolo]
31
32         if $grub_manage {
33                 file { '/etc/default/grub':
34                         # restore to default
35                         source => 'puppet:///modules/grub/etc-default-grub',
36                         notify  => Exec['update-grub']
37                 }
38
39                 file { '/etc/default/grub.d':
40                         ensure => directory,
41                         mode   => '0555',
42                         purge   => true,
43                         force   => true,
44                         recurse => true,
45                         source  => 'puppet:///files/empty/',
46                 }
47
48                 file { '/etc/default/grub.d/puppet-grub-serial.cfg':
49                         ensure => $grub_do_kernel_serial ? { true  => 'present', default => 'absent' },
50                         content  => template('grub/puppet-grub-serial.cfg.erb'),
51                         notify  => Exec['update-grub']
52                 }
53
54                 file { '/etc/default/grub.d/puppet-kernel-serial.cfg':
55                         ensure => $grub_do_grub_serial ? { true  => 'present', default => 'absent' },
56                         content  => template('grub/puppet-kernel-serial.cfg.erb'),
57                         notify  => Exec['update-grub']
58                 }
59
60                 file { '/etc/default/grub.d/puppet-net-ifnames.cfg':
61                         ensure => $grub_do_ifnames ? { true  => 'present', default => 'absent' },
62                         content  => template('grub/puppet-net-ifnames.cfg.erb'),
63                         notify  => Exec['update-grub']
64                 }
65
66                 file { '/etc/default/grub.d/puppet-kernel-nopat.cfg':
67                         ensure => $grub_do_nopat ? { true  => 'present', default => 'absent' },
68                         content  => template('grub/puppet-kernel-nopat.cfg.erb'),
69                         notify  => Exec['update-grub']
70                 }
71
72                 file { '/etc/default/grub.d/puppet-kernel-extra.cfg':
73                         ensure => $grub_do_extra ? { true  => 'present', default => 'absent' },
74                         content  => template('grub/puppet-kernel-extra.cfg.erb'),
75                         notify  => Exec['update-grub']
76                 }
77         }
78
79         exec { 'update-grub':
80                 refreshonly => true,
81                 path        => '/usr/bin:/usr/sbin:/bin:/sbin',
82         }
83 }