Commit 24131493 authored by Simon Josi's avatar Simon Josi
Browse files

refactor module according to new style

parent faa5506b
# manifest/defines.pp
# taken from: http://reductivelabs.com/trac/puppet/wiki/Recipes/KernelModules
define modprobe::kern_module(
$ensure = 'present'
){
# chosse and load default file
case $operatingsystem {
debian: { $modulesfile = '/etc/modules' }
default: { $modulesfile = '/etc/rc.modules' }
}
include modprobe::loadfile
case $ensure {
present: {
exec{"insert_module_${name}":
command => "/bin/echo '/sbin/modprobe ${name}' >> '${modulesfile}' ",
unless => "/bin/grep -qFx '/sbin/modprobe ${name}' '${modulesfile}'"
}
case $operatingsystem {
debian,ubuntu: {
Exec["insert_module_${name}"]{
command => "/bin/echo '${name}' >> '${modulesfile}'",
unless => "/bin/grep -qFx '${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 => "/usr/bin/perl -ni -e 'print unless /^\\Q/sbin/modprobe ${name}\\E\$/' '${modulesfile}'",
onlyif => "/bin/grep -q '^/sbin/modprobe ${name}' '${modulesfile}'",
}
case $operatingsystem {
debian,ubuntu: {
Exec["remove_module_${name}"]{
command => "/usr/bin/perl -ni -e 'print unless /^\\Q${name}\\E\$/' '${modulesfile}'",
onlyif => "/bin/grep -qFx '${name}' '${modulesfile}'",
}
}
}
}
default: {
fail("unknown ensure value ${ensure} to modprobe ${name} on ${fqdn}")
}
}
}
......@@ -11,17 +11,17 @@
# the Free Software Foundation.
#
import 'defines.pp'
class modprobe {
file{"/etc/modprobe.conf":
source => [ "puppet://$server/files/modprobe/${fqdn}/modprobe.conf",
"puppet://$server/files/modprobe/${virtual}/modprobe.conf",
"puppet://$server/files/modprobe/${operatingsystem}/modprobe.conf",
"puppet://$server/files/modprobe/modprobe.conf",
"puppet://$server/modprobe/${virtual}/modprobe.conf",
"puppet://$server/modprobe/${operatingsystem}/modprobe.conf",
"puppet://$server/modprobe/modprobe.conf" ],
file{'/etc/modprobe.conf':
source => [
"puppet://$server/files/modprobe/${fqdn}/modprobe.conf",
"puppet://$server/files/modprobe/${virtual}/modprobe.conf",
"puppet://$server/files/modprobe/${operatingsystem}/modprobe.conf",
"puppet://$server/files/modprobe/modprobe.conf",
"puppet://$server/modprobe/${virtual}/modprobe.conf",
"puppet://$server/modprobe/${operatingsystem}/modprobe.conf",
"puppet://$server/modprobe/modprobe.conf",
],
owner => root, group => 0, mode => 0644;
}
}
# manifest/defines.pp
# taken from: http://reductivelabs.com/trac/puppet/wiki/Recipes/KernelModules
define modprobe::kern_module(
$ensure = 'present'
){
include modprobe::modulesfile
case $operatingsystem {
debian,ubtunu: {
File['/etc/rc.module']{
path => '/etc/modules',
}
}
}
case $ensure {
present: {
exec{"insert_module_$name":
command => "/bin/echo '/sbin/modprobe $name' >> $modulesfile",
unless => "/bin/grep -qFx '/sbin/modprobe $name' $modulesfile",
}
exec{"/sbin/modprobe $name":
unless => "/bin/grep -q '^$name ' /proc/modules"
}
case $operatingsystem {
debian,ubuntu: {
Exec["insert_module_$name"]{
command => "/bin/echo '$name' >> $modulesfile",
unless => "/bin/grep -qFx '$name' $modulesfile",
}
}
}
}
absent: {
exec{"/sbin/modprobe -r $name":
onlyif => "/bin/grep -q '^$name ' /proc/modules"
}
exec{"remove_module_$name":
command => "/bin/sed -i '/^\\/sbin\\/modprobe $name$/d' $modulesfile",
onlyif => "/bin/grep -qFx '/sbin/modprobe $name' $modulesfile",
}
case $operatingsystem {
debian,ubuntu: {
Exec["remove_module_$name"]{
command => "/bin/sed -i '/^$name$/d' $modulesfile",
onlyif => "/bin/grep -qFx '$name' $modulesfile",
}
}
}
}
default: {
fail("Unknown ensure value '$ensure' for modprobe::kern_module!")
}
}
}
# manifests/loadfile.pp
class modprobe::loadfile {
case $operatingsystem {
redhat,centos,fedora: {
file{'/etc/rc.modules':
ensure => file,
mode => 755
}
}
}
}
class modprobe::modulesfile {
file{'/etc/rc.modules':
ensure => file,
owner => root, group => 0, mode => 755;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment