1 Puppet::Type.type(:sysctl_runtime).provide(:sysctl_runtime,
2 :parent => Puppet::Provider
4 desc "This provider changes the runtime values of kernel parameters"
6 commands :sysctl => 'sysctl'
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", {
20 :custom_environment => {}
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
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
41 raise(Puppet::ParseError, "sysctl parameter #{res} wasn't found on this system")
47 sysctl("#{resource[:name]}=#{value}")