ipmi.pp 9.21 KB
Newer Older
1
# base::ipmi: ipmi classes to load, and suppress loading, IPMI client & server.
Bill MacAllister's avatar
Bill MacAllister committed
2
#
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# Most of the time, you should use it like this:
#
# include base::ipmi
#
# That will enable IPMI for physical systems, and will disable IPMI for virtual
# systems (including EC2 systems).  This cannot be overridden.
#
# If you want to disable IPMI (for example, on workstations), use it like this:
#
# class { 'base::ipmi':
#   ensure => absent,
# }
#
# WARNING: On a running system, changing base::ipmi::ensure from present to 
# absent may not work properly, depending on what user-space stuff is using 
# IPMI functionality.  If you get errors, restart.
Adam Lewenberg's avatar
Adam Lewenberg committed
19

20
21
22
class base::ipmi (
  $ensure = present,
) {
Adam Lewenberg's avatar
Adam Lewenberg committed
23

24
  # If we are virtual or on EC2, then explicitly disable IPMI
25
  if $::is_virtual == 'true' or $::ec2_profile == 'default-paravirtual' {
26
27
28
29
30
31
32
33
34
35
36
37
38
39
    $real_ensure = absent
  }
  else {
    $real_ensure = $ensure
  }

  # Check to see what we should do
  case $real_ensure {
    'present': {
      case $::osfamily {
        'Debian': {

          # First, install the ipmitool package
          package { 'ipmitool':
Darren Patterson's avatar
Darren Patterson committed
40
41
            ensure => present;
          }
42
43
44
45
46

          # Next, install the config file
          file { '/etc/default/ipmievd':
            content => template('base/ipmi/etc/default/ipmievd.erb'),
            require => Package['ipmitool'],
Darren Patterson's avatar
Darren Patterson committed
47
          }
48
49
50
51
52
53
54
55
56
57
58

          # Next, install kernel modules
          # For Debian 8+, the package brings in everything it needs by
          # default.  But, if we are re-enabling we need to recover a file that
          # we deleted.  We then have to trigger systemd to load modules.
          if $::operatingsystem == 'Debian' and $::lsbmajdistrelease >= 8 {
            exec { 'Re-create /usr/lib/modules-load.d/ipmievd.conf':
              command => '/usr/bin/apt-get install --reinstall ipmitool',
              creates => '/usr/lib/modules-load.d/ipmievd.conf',
              require => Package['ipmitool'],
              notify  => Exec['Load modules from /usr/lib/modules-load.d/ipmievd.conf'],
Adam Lewenberg's avatar
Adam Lewenberg committed
59
            }
60
61
62
63
64
65
66
67
68
69
            exec { 'Load modules from /usr/lib/modules-load.d/ipmievd.conf':
              command     => 'systemctl restart systemd-modules-load.service',
              notify      => Service['ipmievd'],
              refreshonly => true,
            }

            # Our ipmievd requirements are just the package & the config file.
            $ipmievd_requirements = [Package['ipmitool'],
                                     File['/etc/default/ipmievd'],
                                    ]
Adam Lewenberg's avatar
Adam Lewenberg committed
70
          }
71
72
73
74
75
          # For older Debian, and all Ubuntu, we must load the modules.
          else {
            # Start with ipmi_msghandler
            base::os::kernel_module { 'ipmi_msghandler':
              ensure => present,
Adam Lewenberg's avatar
Adam Lewenberg committed
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

            # Load lots of additional modules
            # In Unbuntu, Kernel 3.13 apparently had one IPMI function compiled
            # into the kernel, meaning there was no driver to load.
            # See Ubuntu bug #1284334
            # Also, there's a kernel module called 'ipmi_watchdog', but it has
            # alot of options to set on load, so we don't try to load it.
            if     $::operatingsystem  == 'Ubuntu'
               and $::kernelmajversion == '3.13'
            {
              $additional_ipmi_modules = [
                'acpi_ipmi',
                'ipmi_devintf',
                'ipmi_poweroff',
              ]
            } else {
              $additional_ipmi_modules = [
                'acpi_ipmi',
                'ipmi_devintf',
                'ipmi_poweroff',
                'ipmi_si',
              ]
            }
            base::os::kernel_module { $additional_ipmi_modules:
              ensure  => present,
              require => Base::Os::Kernel_module['ipmi_msghandler'],
            }

            # Set our requirements for starting ipevd
            $ipmievd_requirements = [Base::Os::Kernel_module['ipmi_devintf'],
                                     File['/etc/default/ipmievd']
                                    ]
          }

          # Finally, start the ipmievd service
          service { 'ipmievd':
            ensure    => running,
            name      => 'ipmievd',
            enable    => true,
            hasstatus => false,
            status    => 'pidof ipmievd',
            require   => $ipmievd_requirements,
          }
        } # Done handling ensure => present for osfamily Debian

        # Catch RHEL and related systems
        'RedHat': {

          # We need to have the OpenIPMI package
          package { 'OpenIPMI':
            ensure => present,
Adam Lewenberg's avatar
Adam Lewenberg committed
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

          # For RHEL 5 and earlier, the client is a separate package
          if $::lsbmajdistrelease <= 5 {
            package { 'OpenIPMI-tools':
              ensure => present,
            }
            $ipmi_package = [Package['OpenIPMI'],
                             Package['OpenIPMI-tools'],
                            ]
          } else {
            $ipmi_package = Package['OpenIPMI']
          }

          # Define and start the services
          # (For RHEL <= 5, we don't need the client to start the service)
          service { 'ipmi':
            ensure    => running,
            name      => 'ipmi',
            enable    => true,
            hasstatus => true,
            require   => $ipmi_package,
          }

          # ipmievd is a separate service, starting with RHEL 5
          service { 'ipmievd':
            ensure    => running,
            name      => 'ipmievd',
            enable    => true,
            hasstatus => true,
            require   => $ipmi_package,
          }
        } # Done handling ensure => present for osfamily RedHat

        default: {
          fail('base::ipmi does not recognize this osfamily')
Adam Lewenberg's avatar
Adam Lewenberg committed
164
        }
165
166
      } # Done checking $osfamily
    } # Done handling ensure => 'present'
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
    'absent': {
      case $::osfamily {
        'Debian': {
          # Stop the IPMI service
          service { 'ipmievd':
            ensure    => stopped,
            name      => 'ipmievd',
            enable    => false,
            hasstatus => false,
            status    => 'pidof ipmievd',
            require   => $ipmievd_requirements,
          }

          # Remove any remaining ipmievd configuration
          file { '/etc/default/ipmievd':
            ensure  => absent,
            require => Service['ipmievd'],
          }

          # Unload lots of additional modules
          # In Unbuntu, Kernel 3.13 apparently had one IPMI function compiled
          # into the kernel, meaning there was no driver to unload.
          # See Ubuntu bug #1284334
          if     $::operatingsystem  == 'Ubuntu'
             and $::kernelmajversion == '3.13'
          {
            $dependent_ipmi_modules = [
              'acpi_ipmi',
              'ipmi_devintf',
              'ipmi_poweroff',
              'ipmi_watchdog'
            ]
            base::os::kernel_module { $dependent_ipmi_modules:
              ensure  => absent,
              require => Service['ipmievd'],
            }
          } else {
            # This is a little more annoying, as we have two dependency levels
            # to deal with.
            $additional_ipmi_modules = [
              'acpi_ipmi',
              'ipmi_devintf',
              'ipmi_poweroff',
              'ipmi_watchdog',
            ]
            base::os::kernel_module { $additional_ipmi_modules:
              ensure  => absent,
              require => Service['ipmievd'],
            }

            $dependent_ipmi_modules = 'ipmi_si'
            base::os::kernel_module { $dependent_ipmi_modules:
              ensure  => absent,
              require => Base::Os::Kernel_module[$additional_ipmi_modules],
            }
          }

          # Unload the ipmi_msghandler, the root for most IPMI stuff
          base::os::kernel_module { 'ipmi_msghandler':
            ensure  => absent,
            require => Base::Os::Kernel_module[$dependent_ipmi_modules],
          }

          # For Debian 8+, make sure modules are not re-loaded on startup
          if $::operatingsystem == 'Debian' and $::lsbmajdistrelease >= 8 {
            file { '/usr/lib/modules-load.d/ipmievd.conf':
              ensure => absent,
            }
          }
Bill MacAllister's avatar
Bill MacAllister committed
237

238
239
240
          # Packages: The IPMI daemon and the client come in one package.
          # Some people might want to keep the client, so we don't delete it.
        } # Done handling ensure => absent for osfamily Debian
Bill MacAllister's avatar
Bill MacAllister committed
241

242
243
244
245
246
247
        'RedHat': {
          # Make sure the IPMI service isn't running
          service { 'ipmi':
            ensure => stopped,
            enable => false,
          }
Bill MacAllister's avatar
Bill MacAllister committed
248

249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
          # Make sure the IPMI packages are uninstalled
          # (We keep tools, but remove the server/driver)
          package { 'OpenIPMI':
            ensure => purged;
          }
        }
        default: {
          fail('base::noipmi does not recognize this OS family')
        }
      } # Dont handling ensure => absent for osfamily RedHat

      # Leave a file marker on the system saying that IPMI is disabled
      file { '/etc/noipmi':
        mode    => '0644',
        content => "ipmi is not supported, or has been disabled in Puppet.\n",
      }
    } # Done handling ensure => absent

    default: {
      fail("Valid values for base::ipmi::ensure are 'present' or 'absent'")
    }
Bill MacAllister's avatar
Bill MacAllister committed
270
271
  }
}