Puppet kernel_module load module

This Puppet module could be called the following way:

# load the Linux kernel module ipmi_devintf
kernel_module { 'ipmi_devintf': ensure => present }

/etc/puppet/modules/kernel_module/manifests/init.pp

# Taken from: http://projects.puppetlabs.com/projects/1/wiki/Kernel_Modules_Patterns
# Made it work under $osfamily rhel
 
define kernel_module ($ensure) {
    case $osfamily {
        redhat: {
          if ! defined(File["/etc/rc.modules"]) {
            file { "/etc/rc.modules": ensure => present, owner => "root", group => "root", mode => 0755 }
          }
        }
    }
    $modulesfile = $osfamily ? { debian => "/etc/modules", redhat => "/etc/rc.modules" }
    case $ensure {
        present: {
            exec { "insert_module_${name}":
                command => $osfamily ? {
                    debian => "/bin/echo '${name}' >> '${modulesfile}'",
                    redhat => "/bin/echo '/sbin/modprobe ${name}' >> '${modulesfile}' "
                },
                unless => $osfamily ? {
                    debian => "/bin/grep -qFx '${name}' '${modulesfile}'",
                    redhat => "/bin/grep -q '^/sbin/modprobe ${name}' '${modulesfile}'"
                }
            }
            exec { "/sbin/modprobe ${name}": unless => "/bin/grep -q '^${name} ' '/proc/modules'" }
        }
        absent: {
            exec { "/sbin/modprobe -r ${name}": onlyif => "/bin/grep -q '^${name} ' '/proc/modules'" }
            exec { "remove_module_${name}":
                command => $osfamily ? {
                    debian => "/usr/bin/perl -ni -e 'print unless /^\\Q${name}\\E\$/' '${modulesfile}'",
                    redhat => "/usr/bin/perl -ni -e 'print unless /^\\Q/sbin/modprobe ${name}\\E\$/' '${modulesfile}'"
                },
                onlyif => $osfamily ? {
                    debian => "/bin/grep -qFx '${name}' '${modulesfile}'",
                    redhat => "/bin/grep -q '^/sbin/modprobe ${name}' '${modulesfile}'"
                }
            }
        }
        default: { err ( "unknown ensure value ${ensure}" ) }
    }
}

Schreibe einen Kommentar