I''ve written my first attempt at a custom puppet function, and it
passes all the suggested test''s from the Puppet documentation, but
when called from a test module it doesn''t seem to be found.
Successful tests...
irb(main):001:0> require ''puppet''
=> true
irb(main):002:0> require ''/etc/puppet/modules/string2hash/
.git/ lib/
irb(main):002:0> require
''/etc/puppet/modules/string2hash/lib/puppet/
parser/functions/string2hash.rb''
=> true
irb(main):003:0> Puppet::Parser::Functions.function(:string2hash)
=> "function_string2hash"
ruby -rpuppet lib/puppet/parser/functions/string2hash.rb returns no
errors
When I try and test the functions ability to even return a correct
value, I get this,
$ puppet --debug -vvv test.pp
Unknown function string2hash at /etc/puppet/modules/test/test.pp:3
This is test.pp...
-----------
$hash_string =
"{\"general\":{\"dump_dir\":\"/backups/misc-sqldumps\",
\"databases\":\"mysql\",\"backup_dir\":\"/etc\"},\"anth\":{\"dump_dir
\":\"/backups/anth-sqldumps\",\"databases\":\"
anth_main anth_students
anth_td
anth_intranet\",\"backup_dir\":\"/var/www/anthropology.tamu.edu
\"}}"
$val = string2hash($hash_string)
notice($val)
This is my function, at /etc/puppet/modules/string2hash/lib/puppet/
parser/functions/string2hash.rb
---------------------
#!/usr/bin/ruby
module Puppet::Parser::Functions
newfunction(:string2hash, :type => :rvalue) do |args|
raise ArgumentError, ("string2hash(): wrong number of
arguments (#{args.length}; must be 1)") if args.length != 1
raise ArgumentError, ("string2hash(): wrong type of
argument (#{args[0].kind_of}; must be string)") if args[0].kind_of?
String
require ''json''
begin
return JSON.parse(args[0])
rescue Exception => exc
raise TypeError, "string2hash(): error
converting string to hash"
end
end
end
I use numerous community functions that work without any type of
"includes" , and can''t seem to figure out why mine is
''unknown'' when
puppet clearly sees it. I''ve restarted both the puppet and
puppetmaster daemon repeatedly.
Thanks
- Trey
--
You received this message because you are subscribed to the Google Groups
"Puppet Users" group.
To post to this group, send email to puppet-users@googlegroups.com.
To unsubscribe from this group, send email to
puppet-users+unsubscribe@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/puppet-users?hl=en.