Re: [Puppet Users] Re: Accessing a fileserver file from a custom function

243 views
Skip to first unread message
Message has been deleted

Nan Liu

unread,
Aug 7, 2012, 5:52:42 PM8/7/12
to puppet...@googlegroups.com
On Tue, Aug 7, 2012 at 11:13 AM, Krzysztof Wilczynski
<krzysztof....@linux.com> wrote:
> Hi James,
>
> [...]
>> How could I acheive this please? I'd rather not hard-code the full path as this would be brittle - how can I "resolve" the puppet:/// url to the actual file location please?
>
> Using "puppet:///" and "file:///" in a way similar to what the File type offers from within a custom function is actually not that straight-forward, sadly. There is a lot of code which deals with resolving these URLs that deals with SSL certificates (since you can request an artifact from different Puppet Master), etc. I found it not that easy to work with outside of the File type, but perhaps somebody was more successful than I was (?) :-)

Here's a function that loads a files in puppet module path which you
can alter to suit your needs:
https://gist.github.com/3289446

This uses the same path as templates so instead of puppet:///, just
module_file(module_name/file_name), and you can look at the template
function for some ideas as well.

Nan

j4m3s

unread,
Aug 8, 2012, 1:44:12 PM8/8/12
to puppet...@googlegroups.com
Fantastic thank you Nan, I'll give this a try tonight.  It should be easy to modify yours to do what I need, thank you for sharing it :)

j4m3s

unread,
Aug 9, 2012, 4:45:43 PM8/9/12
to puppet...@googlegroups.com
I only just noticed this, but I was actually modifying your gist KW to add the puppet:/// parsing.  I've forked it but can't see how to create a pull-request for it (I'm fairly new to gihub I'm afraid).

Anyway, for anyone else wanting the function I've posted it here: https://gist.github.com/3307835.

The next limitation is that it doesn't resolve template paths.  That should probably be in a separate function anyway.

Thank you both for your help.

James.

On Monday, August 6, 2012 10:22:51 AM UTC+1, j4m3s wrote:
Hi

I'm struggling with a relatively straightforward custom function.  All it is designed to do is check for the existence of a file (on the puppetmaster).  It works fine when I specify the full path to the file, but I would like to refer to a file in the module's files directory (e.g. "puppet:///modules/apache/local-modules").


How could I acheive this please?  I'd rather not hard-code the full path as this would be brittle - how can I "resolve" the puppet:/// url to the actual file location please?

(btw I need the function in order to execute classes/ types conditionally depending ont he presence of files - it's for a defined type).

Thanks, James.

Nan Liu

unread,
Aug 9, 2012, 4:50:50 PM8/9/12
to puppet...@googlegroups.com
On Thu, Aug 9, 2012 at 1:45 PM, j4m3s <mrfe...@gmail.com> wrote:
> I only just noticed this, but I was actually modifying your gist KW to add
> the puppet:/// parsing. I've forked it but can't see how to create a
> pull-request for it (I'm fairly new to gihub I'm afraid).
>
> Anyway, for anyone else wanting the function I've posted it here:
> https://gist.github.com/3307835.
>
> The next limitation is that it doesn't resolve template paths. That should
> probably be in a separate function anyway.

I just notice Dan contributed something very similar that's much more
generic to stdlib:

https://github.com/puppetlabs/puppetlabs-stdlib/blob/master/lib/puppet/parser/functions/get_module_path.rb

Thanks,

Nan

j4m3s

unread,
Aug 9, 2012, 5:05:12 PM8/9/12
to puppet...@googlegroups.com
This seems to use the same Puppet::Module.find function that yours did - the only difference I can see is that he gets the environment using
 compiler.environment.to_s
instead of
Puppet[:environment]

 - is that the improved generic part you're referring to?
Reply all
Reply to author
Forward
0 new messages