FAQ
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.

--
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/-/EuZSnRB_2BQJ.
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.

Search Discussions

  • Krzysztof Wilczynski at Aug 7, 2012 at 6:17 pm
    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 (?) :-)

    KW

    --
    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/-/Tm0AmXpDhm8J.
    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.
  • Nan Liu at Aug 7, 2012 at 9:53 pm

    On Tue, Aug 7, 2012 at 11:13 AM, Krzysztof Wilczynski 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

    --
    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.
  • J4m3s at Aug 8, 2012 at 5:44 pm
    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 :)
    On Tuesday, August 7, 2012 10:52:42 PM UTC+1, Nan Liu wrote:

    On Tue, Aug 7, 2012 at 11:13 AM, Krzysztof Wilczynski
    <krzysztof....@linux.com <javascript:>> 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
    --
    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/-/gWjFE5nJ5o8J.
    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.
  • J4m3s at Aug 9, 2012 at 8:45 pm
    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.
    --
    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/-/DGEdCsT0K6UJ.
    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.
  • Nan Liu at Aug 9, 2012 at 8:51 pm

    On Thu, Aug 9, 2012 at 1:45 PM, j4m3s 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

    --
    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.
  • J4m3s at Aug 9, 2012 at 9:10 pm
    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?
    On Thursday, August 9, 2012 9:50:50 PM UTC+1, Nan Liu wrote:

    On Thu, Aug 9, 2012 at 1:45 PM, j4m3s <mrfe...@gmail.com <javascript:>>
    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
    --
    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/-/YAQ0hOk7I40J.
    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.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppuppet-users @
categoriespuppet
postedAug 6, '12 at 6:02p
activeAug 9, '12 at 9:10p
posts7
users3
websitepuppetlabs.com

People

Translate

site design / logo © 2022 Grokbase