Puppet Class: kdump

Defined in:
manifests/init.pp

Summary

Manage kdump

Overview

Examples:

Use default actions of ensuring kdump is stopped

class { 'kdump': }

Example of how to enable kdump

class { 'kdump':
  enable => true,
}

Parameters:

  • enable (Boolean) (defaults to: false)

    Set state of kdump. true - Ensure service running and crashkernel kernel argument set false - Ensure service stopped and crashkernel kernel argument absent

  • crashkernel (String) (defaults to: 'auto')

    Kernel crashkernel argument value

  • crashkernel_bootmode (String) (defaults to: 'all')

    The bootmode for crashkernel kernel argument

  • bootloader_config_path (Optional[Stdlib::AbsolutePath]) (defaults to: undef)

    Path to boot loader config

  • package_name (String) (defaults to: 'kexec-tools')

    Package name that provides kdump.

  • service_name (String) (defaults to: 'kdump')

    Service name for kdump.

  • service_ensure (Optional[String]) (defaults to: undef)

    The service ensure property for kdump.

  • service_enable (Optional[Boolean]) (defaults to: undef)

    The service enable property for kdump.

  • service_hasstatus (Boolean) (defaults to: true)

    The service hasstatus property for kdump.

  • service_hasrestart (Boolean) (defaults to: true)

    The service hasrestart property for kdump.

  • config_path (Stdlib::AbsolutePath) (defaults to: '/etc/kdump.conf')

    The configuration file path for kdump.

  • config_overrides (Hash) (defaults to: {})

    Hash of config values to add to kdump.conf

  • kernel_parameter_provider (String) (defaults to: 'grub2')

    The provider property for the kernel_parameter defined type.

  • manage_kernel_parameter (Boolean) (defaults to: true)

    Controls if kernel_parameter resource is managed

  • grub_kdump_cfg (Optional[String]) (defaults to: undef)

    Path to grub2 kdump config. Only used on Ubuntu.



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
# File 'manifests/init.pp', line 43

class kdump (
  Boolean                        $enable                    = false,
  String                         $crashkernel               = 'auto',
  String                         $crashkernel_bootmode      = 'all',
  Optional[Stdlib::AbsolutePath] $bootloader_config_path    = undef,
  String                         $package_name              = 'kexec-tools',
  String                         $service_name              = 'kdump',
  Optional[String]               $service_ensure            = undef,
  Optional[Boolean]              $service_enable            = undef,
  Boolean                        $service_hasstatus         = true,
  Boolean                        $service_hasrestart        = true,
  Stdlib::AbsolutePath           $config_path               = '/etc/kdump.conf',
  Hash                           $config_overrides          = {},
  String                         $kernel_parameter_provider = 'grub2',
  Boolean                        $manage_kernel_parameter   = true,
  Optional[String]               $grub_kdump_cfg            = undef,
) {
  $osfamily = dig($facts, 'os', 'family')
  if ! ($osfamily in ['RedHat', 'Debian']) {
    fail("Unsupported osfamily: ${osfamily}, module ${module_name} only support RedHat and Debian")
  }

  $config_defaults = {
    'path'              => '/var/crash',
    'core_collector'    => 'makedumpfile -c --message-level 1 -d 31',
    'raw'               => 'UNSET',
    'nfs'               => 'UNSET',
    'nfs4'              => 'UNSET',
    'ssh'               => 'UNSET',
    'ext4'              => 'UNSET',
    'ext3'              => 'UNSET',
    'ext2'              => 'UNSET',
    'minix'             => 'UNSET',
    'btrfs'             => 'UNSET',
    'xfs'               => 'UNSET',
    'link_delay'        => 'UNSET',
    'kdump_post'        => 'UNSET',
    'kdump_pre'         => 'UNSET',
    'extra_bins'        => 'UNSET',
    'extra_modules'     => 'UNSET',
    'options'           => 'UNSET',
    'blacklist'         => 'UNSET',
    'sshkey'            => 'UNSET',
    'default'           => 'UNSET',
    'debug_mem_level'   => 'UNSET',
    'force_rebuild'     => 'UNSET',
  }

  $config = merge($config_defaults, $config_overrides)

  if $enable {
    if $facts['crashkernel'] {
      $service_ensure_default = 'running'
    } else {
      $service_ensure_default = 'stopped'
    }
    $service_ensure_real = pick($service_ensure, $service_ensure_default)
    $service_enable_real = pick($service_enable, true)
    $crashkernel_ensure  = 'present'
  } else {
    $service_ensure_real = 'stopped'
    $service_enable_real = false
    $crashkernel_ensure  = 'absent'
  }

  if $enable {
    if $manage_kernel_parameter {
      kernel_parameter { 'crashkernel':
        ensure   => 'present',
        value    => $crashkernel,
        target   => $bootloader_config_path,
        bootmode => $crashkernel_bootmode,
        provider => $kernel_parameter_provider,
      }
    }

    if $grub_kdump_cfg {
      file { $grub_kdump_cfg:
        ensure  => 'file',
        content => "GRUB_CMDLINE_LINUX_DEFAULT=\"\$GRUB_CMDLINE_LINUX_DEFAULT crashkernel=${crashkernel}\"",
      }
      if $manage_kernel_parameter {
        File[$grub_kdump_cfg] -> Kernel_parameter['crashkernel']
      }
    }

    package { 'kexec-tools':
      ensure => 'installed',
      name   => $package_name,
      before => File['/etc/kdump.conf'],
    }

    file { '/etc/kdump.conf':
      ensure  => 'file',
      path    => $config_path,
      content => template('kdump/kdump.conf.erb'),
      owner   => 'root',
      group   => 'root',
      mode    => '0644',
      notify  => Service['kdump'],
    }

    if ! $facts['crashkernel'] {
      notify { 'kdump':
        message => 'A reboot is required to fully enable the crashkernel',
      }
    }
  } else {
    if $manage_kernel_parameter {
      kernel_parameter { 'crashkernel':
        ensure   => 'absent',
        provider => $kernel_parameter_provider,
      }
    }

    if $grub_kdump_cfg {
      file { $grub_kdump_cfg:
        ensure  => 'file',
        content => "GRUB_CMDLINE_LINUX_DEFAULT=\"\$GRUB_CMDLINE_LINUX_DEFAULT\"",
      }
      if $manage_kernel_parameter {
        File[$grub_kdump_cfg] -> Kernel_parameter['crashkernel']
      }
    }

    if $facts['crashkernel'] {
      notify { 'kdump':
        message => 'A reboot is required to fully disable the crashkernel',
      }
    }
  }

  service { 'kdump':
    ensure     => $service_ensure_real,
    enable     => $service_enable_real,
    name       => $service_name,
    hasstatus  => $service_hasstatus,
    hasrestart => $service_hasrestart,
  }
}