Hello ,
I was trying to write a custom function which would run on puppet master
take input a ini file , parse a section of that ini file and assign
its value to a variable .
Something like
$test = iniread('example.ini', 'Program', 'path')
This would assign the value to test variable when the functions runs on the
puppet master.
iniread.rb file looks like
require 'rubygems'
require 'inifile'
module Puppet::Parser::Functions
newfunction(:iniread, :type => :rvalue) do |args|
raise(Puppet::ParseError, 'inifile read(): Wrong number of arguments ' +
"given (#{args.size} for 3)") if args.size != 3
filename = args[0]
section = args[1]
key = args[2]
file = IniFile.load(filename)
data = file[section]
value = data[key]
return value
end
end
It gives an error while running
Error 400 on SERVER: undefined method `[]' for nil:NilClass at
/etc/puppetlabs/puppet/modules/example/manifests/init.pp:45
init.pp has
$test =iniread("example.ini", "Program", "path")
Doing that in ruby works
require 'inifile'
filename = ARGV[0]
section = ARGV[1]
key = ARGV[2]
file = IniFile.load(filename)
data = file[section]
InstPath = data[key]
puts InstPath
Help to this would be really appreciated.
Regards,
Ritesh
--
You received this message because you are subscribed to the Google Groups
"Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to puppet-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/puppet-users/460bb860-e8cb-4022-a1a3-47fb4b0015e5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.