Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#
# Definition for loading kernel modules.
# This is taken directly from:
# http://reductivelabs.com/trac/puppet/wiki/Recipes/KernelModules
define base::os::kernel-module ($ensure) {
$modulesfile = $operatingsystem ? {
'debian' => '/etc/modules',
'ubuntu' => '/etc/modules',
'redhat' => '/etc/rc.modules',
}
case $operatingsystem {
'redhat': {
file { '/etc/rc.modules':
ensure => file,
mode => 755
}
}
}
case $ensure {
present: {
exec { "insert_module_${name}":
command => $operatingsystem ? {
'debian' => "/bin/echo '${name}' >> '${modulesfile}'",
'ubuntu' => "/bin/echo '${name}' >> '${modulesfile}'",
'redhat' => "/bin/echo '/sbin/modprobe ${name}' >> '${modulesfile}'",
},
unless => "/bin/grep -q '${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 => $operatingsystem ? {
'debian' => "/usr/bin/perl -ni -e 'print unless /^\\Q${name}\\E\$/' '${modulesfile}'",
'ubuntu' => "/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 => $operatingsystem ? {
'debian' => "/bin/grep -qFx '${name}' '${modulesfile}'",
'ubuntu' => "/bin/grep -qFx '${name}' '${modulesfile}'",
'redhat' => "/bin/grep -q '^/sbin/modprobe ${name}' '${modulesfile}'",
},
}
}
default: { err ( "unknown ensure value ${ensure}" ) }
}
}