Ask Your Question

How do I read a file from a custom function?

asked 2014-03-07 11:26:32 -0500

robrwo gravatar image

I have a custom function that reads a file of the form


The file is on the Puppetmaster, and the pe-puppet user has the ability to read the file. But when it's run, it returns nothing. It seems as if the function isn't being run at all, especially when I hardcode a return value.

The function is:

module Puppet::Parser::Functions
  newfunction(:get_config, :type => :rvalue, :doc => <<-EOS
  ) do |arguments|

    raise(Puppet::ParseError, "get_config(): Wrong number of arguments " +
      "given (#{arguments.size} for 2)") if arguments.size < 2

    filename = arguments[0]

    unless filename.is_a? String ...
edit retag flag offensive close merge delete


what is the absolute pathname of the file where you've defined your function? Can you please provide the sample manifest where you are using your function? What do you ...(more)

Stefan gravatar imageStefan ( 2014-03-07 12:59:07 -0500 )edit

in `modules/get_config/lib/puppet/parser/functions/get_config.rb`. There are no messages in the puppet master log, and when trying to put the output in a template, it seems ...(more)

robrwo gravatar imagerobrwo ( 2014-03-10 10:00:45 -0500 )edit

Ok, it works after all. Turned out to be a typo in a template (which for unknown reasons, did not throw an error.)

robrwo gravatar imagerobrwo ( 2014-03-10 11:55:04 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2014-03-10 03:37:31 -0500

spend gravatar image

Works OK for me, using these file locations as an example...

Function file saved as '..../modules/custom/lib/puppet/parser/functions/get_config.rb'

Test file created : "/tmp/test.dat" testvar=testval

Test manifest: "test.pp" $test = get_config("/tmp/test.dat","testvar","defaulttestval") notify { "Result: ${test}" : }

$ puppet apply test.pp Notice: Compiled catalog for srv3.dspen.loc in environment production in 0.07 seconds Notice: Result: testval

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2014-03-07 11:26:32 -0500

Seen: 487 times

Last updated: Mar 10 '14