My custom function looks like this :
module Puppet::Parser::Functions
newfunction(:pattern_in_file, :type => :rvalue) do |args|
filename = args[0]
pattern = args[1]
value = false
File.open(filename) do |f|
f.each_line do |line|
return true if line.match(pattern)
end
end
false
end
end
ruby -rpuppet and irb tests to see if the function is seen by puppet end successfully without any error.
Inside the manifests callings
pattern_in_file('/etc/fstab', '/usr')
don't complain or print anything,
If I use :
$getval = pattern_in_file('/etc/fstab', '/usr')
It complains the following :
Error: Could not retrieve catalog from remote server: Error 400 on SERVER: Function 'pattern_in_file' does not return a value at /etc/puppet/modules/mname/manifests/datavers.pp:3 on node node_name
Any suggestion why the return doesn't work ?