try again, with puppetforge modules, correctly included now
[mirror/dsa-puppet.git] / 3rdparty / modules / sysctl / lib / puppet / provider / sysctl_runtime / sysctl_runtime.rb
1 Puppet::Type.type(:sysctl_runtime).provide(:sysctl_runtime,
2                                     :parent => Puppet::Provider
3                                    ) do
4   desc "This provider changes the runtime values of kernel parameters"
5
6   commands :sysctl => 'sysctl'
7
8   mk_resource_methods
9
10   def self.instances
11     #we don't use here the sysctl command to be able
12     #to disable combining of stderr/stdout output.
13     #Sysctl produces mixed output in case of error,
14     #and it can't be parsed.
15     #https://ask.puppetlabs.com/question/6299/combine-false-for-provider-commands/
16     executor = (Facter.value(:puppetversion).to_i < 3) ? Puppet::Util : Puppet::Util::Execution
17     output = executor.execute("#{Puppet::Util.which('sysctl')} -a", {
18       :failonfail         => true,
19       :combine            => false,
20       :custom_environment => {}
21     })
22     output.split("\n").collect do |line|
23       # lovely linux shows "fs.dir-notify-enable = 1"
24       # lovely openbsd shows "fs.dir-notify-enable=1"
25       name, val = line.split(/\s?[=:]\s?/,2)
26       if name && val # maybe the line didn't match key = val
27         new(
28           :name => name,
29           :val  => val
30         )
31       end
32     end.compact
33   end
34
35   def self.prefetch(resources)
36     sysctl_flags = instances
37     resources.keys.each do |res|
38       if provider = sysctl_flags.find{ |sres| sres.name == res }
39         resources[res].provider = provider
40       else
41         raise(Puppet::ParseError, "sysctl parameter #{res} wasn't found on this system")
42       end
43     end
44   end
45
46   def val=(value)
47     sysctl("#{resource[:name]}=#{value}")
48   end
49
50 end