FAQ
Hello,

Is it possible to override a resource that is created with the
create_resource function?

This manifest does not compile:

------------------
$hash = { 'msg' => { message => 'woof' } }

class base {
create_resources('notify', $hash)
}

class over inherits base {
Notify['msg'] { message => 'meow' }
}

class { 'base': }
class { 'over': }
-----------------

Thanks,

-Luke

--
Luke Bigum

Information Systems
Ph: +44 (0) 20 3192 2520
luke.bigum@lmax.com | http://www.lmax.com
LMAX, Yellow Building, 1A Nicholas Road, London W11 4AN


FX and CFDs are leveraged products that can result in losses exceeding
your deposit. They are not suitable for everyone so please ensure you
fully understand the risks involved. The information in this email is not
directed at residents of the United States of America or any other
jurisdiction where trading in CFDs and/or FX is restricted or prohibited
by local laws or regulations.

The information in this email and any attachment is confidential and is
intended only for the named recipient(s). The email may not be disclosed
or used by any person other than the addressee, nor may it be copied in
any way. If you are not the intended recipient please notify the sender
immediately and delete any copies of this message. Any unauthorised
copying, disclosure or distribution of the material in this e-mail is
strictly forbidden.

LMAX operates a multilateral trading facility. Authorised and regulated
by the Financial Services Authority (firm registration number 509778) and
is registered in England and Wales (number 06505809).
Our registered address is Yellow Building, 1A Nicholas Road, London, W11
4AN.

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

Search Discussions

  • Nan Liu at May 11, 2012 at 5:30 pm

    On Fri, May 11, 2012 at 3:57 AM, Luke Bigum wrote:
    Hello,

    Is it possible to override a resource that is created with the
    create_resource function?

    This manifest does not compile:

    ------------------
    $hash = { 'msg' => { message => 'woof' } }

    class base {
    create_resources('notify', $hash)
    }

    class over inherits base {
    Notify['msg'] { message => 'meow' }
    }

    class { 'base': }
    class { 'over': }
    -----------------
    You can't declare both classes, but you can override resources in
    class over, because we can merge hash values before calling create
    resource.

    The example here is obviously contrived, but I assume you have a
    bigger hash you want to merge. The merge function comes from stdlib:

    # don't inherit base we can create the resources here instead.
    class over {
    $local_setting = { 'msg' => { message => 'meow'} }
    $newhash = merge($local_setting, $hash)
    create_resource('notify', $newhash}
    }

    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.
  • Luke Bigum at May 14, 2012 at 8:08 am
    Hi Nan,

    Thanks for the reply. I did start thinking about how I could use the
    merge function to achieve what I wanted. I was messing around with
    something like this (which obviously doesn't work because of the
    inheritance order):

    -----------------------
    $hash = { 'msg' => { message => 'woof' } }

    class base($more_hash = undef) {
    if ($more_hash) {
    $real_hash = merge($more_hash, $hash)
    } else {
    $real_hash = $hash
    }
    create_resources('notify', $real_hash)
    }

    class over inherits base {
    $more_hash = { 'msg' => { message => 'meow' } }
    }

    class { 'base': }
    class { 'over': }
    ------------------------

    This question relates to my other post about a sysctl class. In my case
    I'd like the create_resources call to always reside within class 'base'
    as that would be a standard declaration on all nodes - and that's my
    real problem. Class 'base' can't be in a standard list of declarations
    if it's ever going to take a parameter and be configurable. I have yet
    to find the perfect balance of common things to manage and
    configurability ;-)

    -Luke
    On 11/05/12 18:29, Nan Liu wrote:
    On Fri, May 11, 2012 at 3:57 AM, Luke Bigumwrote:
    Hello,

    Is it possible to override a resource that is created with the
    create_resource function?

    This manifest does not compile:

    ------------------
    $hash = { 'msg' => { message => 'woof' } }

    class base {
    create_resources('notify', $hash)
    }

    class over inherits base {
    Notify['msg'] { message => 'meow' }
    }

    class { 'base': }
    class { 'over': }
    -----------------
    You can't declare both classes, but you can override resources in
    class over, because we can merge hash values before calling create
    resource.

    The example here is obviously contrived, but I assume you have a
    bigger hash you want to merge. The merge function comes from stdlib:

    # don't inherit base we can create the resources here instead.
    class over {
    $local_setting = { 'msg' => { message => 'meow'} }
    $newhash = merge($local_setting, $hash)
    create_resource('notify', $newhash}
    }

    Thanks,

    Nan

    --
    Luke Bigum

    Information Systems
    Ph: +44 (0) 20 3192 2520
    luke.bigum@lmax.com | http://www.lmax.com
    LMAX, Yellow Building, 1A Nicholas Road, London W11 4AN


    FX and CFDs are leveraged products that can result in losses exceeding
    your deposit. They are not suitable for everyone so please ensure you
    fully understand the risks involved. The information in this email is not
    directed at residents of the United States of America or any other
    jurisdiction where trading in CFDs and/or FX is restricted or prohibited
    by local laws or regulations.

    The information in this email and any attachment is confidential and is
    intended only for the named recipient(s). The email may not be disclosed
    or used by any person other than the addressee, nor may it be copied in
    any way. If you are not the intended recipient please notify the sender
    immediately and delete any copies of this message. Any unauthorised
    copying, disclosure or distribution of the material in this e-mail is
    strictly forbidden.

    LMAX operates a multilateral trading facility. Authorised and regulated
    by the Financial Services Authority (firm registration number 509778) and
    is registered in England and Wales (number 06505809).
    Our registered address is Yellow Building, 1A Nicholas Road, London, W11
    4AN.

    --
    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.
  • Brian Gallew at May 14, 2012 at 8:23 am
    Your requirements are moving you to the "must use an ENC or Hiera or Ruby
    DSL" camp. Puppet's static typing will absolutely prevent you from doing
    this the way you seem to be thinking about it. At this point, your easiest
    answer is probably to use Hiera for looking up the value of this hash.
    On Mon, May 14, 2012 at 1:08 AM, Luke Bigum wrote:

    Hi Nan,

    Thanks for the reply. I did start thinking about how I could use the merge
    function to achieve what I wanted. I was messing around with something like
    this (which obviously doesn't work because of the inheritance order):

    -----------------------

    $hash = { 'msg' => { message => 'woof' } }

    class base($more_hash = undef) {
    if ($more_hash) {
    $real_hash = merge($more_hash, $hash)
    } else {
    $real_hash = $hash
    }
    create_resources('notify', $real_hash)
    }

    class over inherits base {
    $more_hash = { 'msg' => { message => 'meow' } }
    }

    class { 'base': }
    class { 'over': }
    ------------------------

    This question relates to my other post about a sysctl class. In my case
    I'd like the create_resources call to always reside within class 'base' as
    that would be a standard declaration on all nodes - and that's my real
    problem. Class 'base' can't be in a standard list of declarations if it's
    ever going to take a parameter and be configurable. I have yet to find the
    perfect balance of common things to manage and configurability ;-)

    -Luke

    On 11/05/12 18:29, Nan Liu wrote:

    On Fri, May 11, 2012 at 3:57 AM, Luke Bigumwrote:
    Hello,

    Is it possible to override a resource that is created with the
    create_resource function?

    This manifest does not compile:

    ------------------
    $hash = { 'msg' => { message => 'woof' } }

    class base {
    create_resources('notify', $hash)
    }

    class over inherits base {
    Notify['msg'] { message => 'meow' }
    }

    class { 'base': }
    class { 'over': }
    -----------------
    You can't declare both classes, but you can override resources in
    class over, because we can merge hash values before calling create
    resource.

    The example here is obviously contrived, but I assume you have a
    bigger hash you want to merge. The merge function comes from stdlib:

    # don't inherit base we can create the resources here instead.
    class over {
    $local_setting = { 'msg' => { message => 'meow'} }
    $newhash = merge($local_setting, $hash)
    create_resource('notify', $newhash}
    }

    Thanks,

    Nan
    --
    Luke Bigum

    Information Systems
    Ph: +44 (0) 20 3192 2520
    luke.bigum@lmax.com | http://www.lmax.com
    LMAX, Yellow Building, 1A Nicholas Road, London W11 4AN


    FX and CFDs are leveraged products that can result in losses exceeding
    your deposit. They are not suitable for everyone so please ensure you
    fully understand the risks involved. The information in this email is not
    directed at residents of the United States of America or any other
    jurisdiction where trading in CFDs and/or FX is restricted or prohibited
    by local laws or regulations.

    The information in this email and any attachment is confidential and is
    intended only for the named recipient(s). The email may not be disclosed
    or used by any person other than the addressee, nor may it be copied in
    any way. If you are not the intended recipient please notify the sender
    immediately and delete any copies of this message. Any unauthorised
    copying, disclosure or distribution of the material in this e-mail is
    strictly forbidden.

    LMAX operates a multilateral trading facility. Authorised and regulated
    by the Financial Services Authority (firm registration number 509778) and
    is registered in England and Wales (number 06505809). Our registered
    address is Yellow Building, 1A Nicholas Road, London, W11
    4AN.

    --
    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 <puppet-users%2Bunsubscribe@googlegroups.com>.
    For more options, visit this group at http://groups.google.com/**
    group/puppet-users?hl=en<http://groups.google.com/group/puppet-users?hl=en>
    .
    --
    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
postedMay 11, '12 at 10:57a
activeMay 14, '12 at 8:23a
posts4
users3
websitepuppetlabs.com

People

Translate

site design / logo © 2022 Grokbase