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? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Luke Kanies
2008-Jun-04 18:30 UTC
[Puppet Users] Re: Custom function: where to put the file?
On Jun 4, 2008, at 11:11 AM, Mike wrote:> 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 > catalogThis indicates to me that your server is finding the function and it''s never returning. Try running your function separately. For instance, here''s a test script I recently wrote for a demo function: describe Puppet::Parser::Functions.function(:spectest) do it "should get added to the list of functions" do Puppet::Parser::Functions.function(:spectest).should_not be_false end it "should be a statement" do Puppet::Parser::Functions.should_not be_rvalue(:spectest) end it "should create a function named ''spectest''" do Puppet::Parser::Scope.instance_methods.should be_include("function_spectest") end describe "when being executed" do it "should send an error message with its arguments" do Puppet.expects(:err).with("one two") Puppet::Parser::Scope.new.function_spectest(%w{one two}) end end end -- Take the utmost trouble to find the right thing to say, and then say it with the utmost levity. -- George Bernard Shaw --------------------------------------------------------------------- Luke Kanies | http://reductivelabs.com | http://madstop.com --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thanks, Luke. Actually I see the timeout behavior fairly frequently. It''s become a signal to me that my configuration is busted somehow. Usually I''ll follow these steps to confirm the signal: 1. Kill the running puppet check. 2. service puppetmaster restart 3. Start the puppet check again, and immediately see an error on the client that I forgot a closing brace or something like that on the server. I have assumed this was a feature of Puppet, where clients will retry a few times to give the foolhardy sysadmin time to fix the bug he introduced while editing the live puppetmaster configuration. Anyway, in this case, I don''t think failure to return is the problem. There are two reasons I think this: 1. The behavior is the same even if I remove the file_last_line.rb entirely from the filesystem. 2. I''ve tried both the file_last_line.rb and rand.rb sample functions given in the tutorial, and both behave the same way. It seems very unlikely that rand.rb is looping or hanging. I''m afraid I know next to nothing about Ruby, so I don''t know what to do with your test script. I tried pasting it into a file called test.rb and then executing "ruby test.rb" on the command line, and it said "uninitialized constant Puppet (NameError)." I expect at least one reader''s answer at this point will be "go away and come back when you''ve learned Ruby; you have no business trying to write custom Puppet functions until you have done so." But I''ll let someone else start that flamewar. :) On Jun 4, 11:30 am, Luke Kanies <l...@madstop.com> wrote:> On Jun 4, 2008, at 11:11 AM, Mike wrote: > > > 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 > > This indicates to me that your server is finding the function and it''s > never returning. > > Try running your function separately. For instance, here''s a test > script I recently wrote for a demo function: > > describe Puppet::Parser::Functions.function(:spectest) do > it "should get added to the list of functions" do > Puppet::Parser::Functions.function(:spectest).should_not > be_false > end > > it "should be a statement" do > Puppet::Parser::Functions.should_not be_rvalue(:spectest) > end > > it "should create a function named ''spectest''" do > Puppet::Parser::Scope.instance_methods.should > be_include("function_spectest") > end > > describe "when being executed" do > it "should send an error message with its arguments" do > Puppet.expects(:err).with("one two") > Puppet::Parser::Scope.new.function_spectest(%w{one two}) > end > end > end > > -- > Take the utmost trouble to find the right thing to say, and then say > it with the utmost levity. -- George Bernard Shaw > --------------------------------------------------------------------- > Luke Kanies |http://reductivelabs.com|http://madstop.com--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hold on, I just discovered generate(). This seems to provide the functionality I need -- specifically, calling an external script (written in any language :) to inject an external value into a Puppet variable. And thus I get to delay solving the custom-function puzzle until another day. On Jun 4, 11:56 am, Mike <mike.t...@gmail.com> wrote:> Thanks, Luke. Actually I see the timeout behavior fairly frequently. > It''s become a signal to me that my configuration is busted somehow. > Usually I''ll follow these steps to confirm the signal: > > 1. Kill the running puppet check. > 2. service puppetmaster restart > 3. Start the puppet check again, and immediately see an error on the > client that I forgot a closing brace or something like that on the > server. > > I have assumed this was a feature of Puppet, where clients will retry > a few times to give the foolhardy sysadmin time to fix the bug he > introduced while editing the live puppetmaster configuration. > > Anyway, in this case, I don''t think failure to return is the problem. > There are two reasons I think this: > > 1. The behavior is the same even if I remove the file_last_line.rb > entirely from the filesystem. > > 2. I''ve tried both the file_last_line.rb and rand.rb sample functions > given in the tutorial, and both behave the same way. It seems very > unlikely that rand.rb is looping or hanging. > > I''m afraid I know next to nothing about Ruby, so I don''t know what to > do with your test script. I tried pasting it into a file called > test.rb and then executing "ruby test.rb" on the command line, and it > said "uninitialized constant Puppet (NameError)." > > I expect at least one reader''s answer at this point will be "go away > and come back when you''ve learned Ruby; you have no business trying to > write custom Puppet functions until you have done so." But I''ll let > someone else start that flamewar. :) > > On Jun 4, 11:30 am, Luke Kanies <l...@madstop.com> wrote: > > > On Jun 4, 2008, at 11:11 AM, Mike wrote: > > > > 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 > > > This indicates to me that your server is finding the function and it''s > > never returning. > > > Try running your function separately. For instance, here''s a test > > script I recently wrote for a demo function: > > > describe Puppet::Parser::Functions.function(:spectest) do > > it "should get added to the list of functions" do > > Puppet::Parser::Functions.function(:spectest).should_not > > be_false > > end > > > it "should be a statement" do > > Puppet::Parser::Functions.should_not be_rvalue(:spectest) > > end > > > it "should create a function named ''spectest''" do > > Puppet::Parser::Scope.instance_methods.should > > be_include("function_spectest") > > end > > > describe "when being executed" do > > it "should send an error message with its arguments" do > > Puppet.expects(:err).with("one two") > > Puppet::Parser::Scope.new.function_spectest(%w{one two}) > > end > > end > > end > > > -- > > Take the utmost trouble to find the right thing to say, and then say > > it with the utmost levity. -- George Bernard Shaw > > --------------------------------------------------------------------- > > Luke Kanies |http://reductivelabs.com|http://madstop.com--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---