[Puppet Users] Custom function: where to put the file?

Mike
Wed, 04 Jun 2008 18:11:12 -0000

I''m failing to follow the "Writing your own functions"
tutorial with
my Red Hat-derived Linux, 0.24.4, master running on same machine as
puppet.

My file is called file_last_line.rb and its contents are this:

module Puppet::Parser::Functions
  newfunction(:file_last_line, :type => :rvalue) do |args|
    self.interp.newfile(args[0])
    lines = IO.readlines(args[0])
    lines[lines.length - 1]
  end
end

I have a test node containing these lines:

  alert("hello")
  alert(file_last_line("/etc/
a_file_I_know_exists_and_is_world_readable"))

and I''ve put my file in all of the following places:

# find / -name file_last_line.rb
/etc/puppet/modules/puppet/parser/functions/file_last_line.rb
/etc/puppet/modules/lib/puppet/parser/functions/file_last_line.rb
/usr/lib/ruby/site_ruby/1.8/puppet/parser/file_last_line.rb
/usr/lib/ruby/site_ruby/1.8/puppet/parser/functions/file_last_line.rb
/var/lib/puppet/lib/puppet/parser/functions/file_last_line.rb

# /usr/sbin/puppetmasterd --configprint all emits this (elided):

libdir = /var/lib/puppet/lib
modulepath = /etc/puppet/modules:/usr/share/puppet/modules

All I ever see in /var/log/messages on a client run is this:

Jun  4 13:50:08 myhostname puppetmasterd[23529]:
(Scope(Node[myhostname.mycompany.com]))  hello
Jun  4 13:52:00 myhostname puppetd[23536]: Configuration retrieval
timed out
Jun  4 13:52:01 myhostname puppetd[23536]: Not using cache on failed
catalog

I feel that I''ve followed the tutorial as best as I can (with the
exception that I don''t know how to determine the "Ruby
$LOAD_PATH"),
but I''m not seeing enough diagnostic information to figure this out on
my own.

Questions I''d like to know:

- Is there a way to tell where Puppet is looking for a custom
function? E.g., "Expected to find custom function implementation at /
path/to/functions/file_last_line.rb but found no such file"?

- Are there files in a standard Puppet installation that I could
expect to reliably find next to the expected directory? For example, I
found "functions.rb" next to the first place I created the functions
directory in /usr/lib/ruby/site_ruby/1.8/puppet/parser/ -- if you''ve
successfully run a custom function, did you also find this file next
to the functions directory that you created?

- For those of you close enough to Puppet internals that you can tell
what''s wrong without any diagnostic information, do you feel that the
problem is that the file location is incorrect? Or is it something
else?