FAQ
I have a hash defined containing some static information. This exists
within a custom function for Puppet.

I wish to share this code with a ruby test harness I'm writing; there will
be additional resources that both Puppet and the test harness can make use
of.

My question is - what's the best way to achieve this?

I've seen in custom function examples that require statements are specified
outside the puppet custom function template. However, if I try to move my
static hash definition to this scope then it's no longer visible to the
custom function.

How may I access static info like this from standard ruby, and what scope
in the puppet custom function definition should it occupy?

Thank you for your time.

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

  • Jeff McCune at Nov 30, 2012 at 4:16 pm

    On Fri, Nov 30, 2012 at 4:30 AM, KomodoDave wrote:
    I have a hash defined containing some static information. This exists within
    a custom function for Puppet.

    I wish to share this code with a ruby test harness I'm writing; there will
    be additional resources that both Puppet and the test harness can make use
    of.

    My question is - what's the best way to achieve this?

    I've seen in custom function examples that require statements are specified
    outside the puppet custom function template. However, if I try to move my
    static hash definition to this scope then it's no longer visible to the
    custom function.

    How may I access static info like this from standard ruby, and what scope in
    the puppet custom function definition should it occupy?

    Thank you for your time.
    I'd factor out the static information into a class that both the
    function and the test harness are able to instantiate. Do you have
    your code published somewhere we could comment on it? This might make
    it easier to make a suggestion.

    -Jeff

    --
    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.
  • Dave Brown at Nov 30, 2012 at 4:42 pm
    Sure thing, here you are:

    ## Usage:## artifacts()## Returns:## Puppet hash containing
    artifact info.## @author N David Brownmodule Puppet::Parser::Functions
    newfunction(:artifacts, :type => :rvalue) do |args|
    # Info common to all artifacts.
    _common = {
    'pkg' => 'tar.gz',
    'ver' => '7.1.0.fuse-041',
    'repo' =>
    'http://maven/nexus/content/groups/fusesource-features-group'
    }

    # Bespoke info for artifacts.
    _artifacts = {
    'fabric' => {
    'id' => 'fuse-fabric',
    'grp' => 'org.fusesource.fabric'
    }.merge!(_common), # merge in common artifact info
    'fmc' => {
    'id' => 'fmc-distro',
    'grp' => 'org.fusesource.fmc'
    }.merge!(_common) # merge in common artifact info
    }

    return _artifacts
    endend

    Earlier I was pointing out that moving _common and _artifacts above the
    module... line means they can't be accessed by the new function definition.

    I thought that might work to make them accessible from a require in a
    standard Ruby file, having seen require be used at that scope in example
    Puppet custom functions in the official documentation.

    Cheers,

    Dave
    -- N David Brown | Software Developer | Development Support and Integration
    Team | Ocado Ltd | T: 01707 382197 | M: 07908 623472


    On 30 November 2012 16:15, Jeff McCune wrote:
    On Fri, Nov 30, 2012 at 4:30 AM, KomodoDave wrote:
    I have a hash defined containing some static information. This exists within
    a custom function for Puppet.

    I wish to share this code with a ruby test harness I'm writing; there will
    be additional resources that both Puppet and the test harness can make use
    of.

    My question is - what's the best way to achieve this?

    I've seen in custom function examples that require statements are specified
    outside the puppet custom function template. However, if I try to move my
    static hash definition to this scope then it's no longer visible to the
    custom function.

    How may I access static info like this from standard ruby, and what scope in
    the puppet custom function definition should it occupy?

    Thank you for your time.
    I'd factor out the static information into a class that both the
    function and the test harness are able to instantiate. Do you have
    your code published somewhere we could comment on it? This might make
    it easier to make a suggestion.

    -Jeff

    --
    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.
    This message has been checked for all known viruses by the Postini Virus Control Centre.

    --
    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.
  • Jeff McCune at Nov 30, 2012 at 7:23 pm

    On Fri, Nov 30, 2012 at 8:42 AM, Dave Brown wrote:
    Sure thing, here you are:
    This conversation might be better suited to the puppet-dev mailing
    list. I recommend posting follow up messages there. _common and
    _artifacts are local variables and won't be accessible outside of the
    scope they're defined in. I recommend turning the data structures
    into constants or methods.

    Hope this helps,
    -Jeff

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

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppuppet-users @
categoriespuppet
postedNov 30, '12 at 12:37p
activeNov 30, '12 at 7:23p
posts4
users2
websitepuppetlabs.com

2 users in discussion

Jeff McCune: 2 posts Dave Brown: 2 posts

People

Translate

site design / logo © 2022 Grokbase