kern_module.pp 1.41 KB
Newer Older
1
define modprobe::kern_module(
2
  $ensure = 'present'
3
){
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
  case $operatingsystem {
    debian,ubuntu: {
      $modulesfile = '/etc/modules'
    }
    default: {
      $modulesfile = '/etc/rc.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 {
Simon Josi's avatar
Simon Josi committed
22
        debian,ubuntu: {
23
24
25
26
          Exec["insert_module_$name"]{
            command => "/bin/echo '$name' >> $modulesfile",
            unless => "/bin/grep -qFx '$name' $modulesfile",
          }
Simon Josi's avatar
Simon Josi committed
27
        }
28
      }
29
    }
30
31
32
33
34
35
36
37
38
39
40
41
42
43
    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",
          }
44
        }
45
46
47
48
      }
    }
    default: {
      fail("Unknown ensure value '$ensure' for modprobe::kern_module!")
49
    }
50
  }
51
}