I am thinking about loading some paramters from a external file for my 
souces.  Eg,

class test { 
         
        ## set parameters. 
        load_from_yaml("puppet:///modules/test/config.yaml")
}

I already have a simple function which can load from the abspath 


module Puppet::Parser::Functions
  
    newfunction(:load_from_yaml) do |args|

        unless args.length == 1
            raise Puppet::ParseError, ("loadyaml(): wrong number of 
arguments (#{args.length}; must be 1)")
        end 
        path = args[0]
        raise Puppet::ParseError, ("path must be absolute") unless 
Puppet::Util.absolute_path?(path)
        params = YAML.load_file(path)
        params.each do |param, value|
            setvar(param, value)
        end
    end 
end 


supporting  puppet url format would be a great help here. 


On Tuesday, November 13, 2012 4:48:15 AM UTC+8, Jeff McCune wrote:
>
> On Sat, Nov 10, 2012 at 9:22 AM, woosley. xu. <[email protected]<javascript:>
> > wrote:
>
>> Hi all, 
>>        I want to parse the puppet url in my customizes functions.  Eg, 
>>         
>>
>>  module Puppet::Parser::Functions
>>       newfunction(:load_file, ) do |arg|
>>            path = get_real_path(arg[0])
>>            load_file_content(path)
>>       end
>>     end
>>
>>
>> suppose arg[0] is a puppet file url: 
>> puppt:///module/someModule/fileName.yaml, how can I parse this url and get 
>> the real os path of that file? 
>>
>>
> There isn't really a good and reliable way I can think of to do this. 
>  Functions are executed when a catalog is being compiled, but there is no 
> guarantee that the host compiling a catalog is also the same host that will 
> serve up file content and metadata.  In multiple-master configurations the 
> fileserver puppet master processes are often running on different hosts 
> than the catalog compiler puppet master processes.
>
> What problem are you trying to solve?  Perhaps there is another approach 
> that does not require translating Puppet URI's to real paths.
>
> -Jeff
>

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/puppet-users/-/5wxc6-yDDJkJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/puppet-users?hl=en.

Reply via email to