FAQ
I am trying to create a "template" for all my servers. I have 2
configurations. An NTP client (which is taken care of in the baseclass
class. I want to create an override specific for the NTP servers by
declaring something specific in the node declaration. Something like
"baseclass::ntp:restrict => true,". Or alternatively, how would I change
one of the already declared variable from baseclass::ntp?

Does anyone have any ideas host to do this?

This is what I have so far:

templates.pp

class baseclass {
include defaultusers
include sudoers
include issue

class { ntp:
ensure => running,
servers => ['ntpserver1.host.com',
'ntpserver2.host.com',],
autoupdate => false,
}
}




nodes.pp

node default {
include baseclass
}

node "ntpserver1.host.com" inherits default {
<some code here to declare new variable in baseclass::ntp>
<some code here to change existing variable, such as "ensure">
}

--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users+unsubscribe@googlegroups.com.
To post to this group, send email to puppet-users@googlegroups.com.
Visit this group at http://groups.google.com/group/puppet-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

  • Peter Meier at Mar 26, 2013 at 12:34 pm
    Does anyone have any ideas host to do this?
    Do not use node inheritance, simply don't - it will hurt you badly at
    some point.

    It does not work in the same way as class inheritance does. And also
    class inheritance should not used that widely (more or less only if
    you need to overwrite values for resources, that aren't assignable as
    parameter from an external source.

    Instead use hiera and design your hierarchy there, then you will have
    much more flexibility.

    ~pete


    --
    You received this message because you are subscribed to the Google Groups "Puppet Users" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users+unsubscribe@googlegroups.com.
    To post to this group, send email to puppet-users@googlegroups.com.
    Visit this group at http://groups.google.com/group/puppet-users?hl=en.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Jcbollinger at Mar 26, 2013 at 1:50 pm

    On Monday, March 25, 2013 9:14:51 PM UTC-5, Cesar Covarrubias wrote:
    I am trying to create a "template" for all my servers. I have 2
    configurations. An NTP client (which is taken care of in the baseclass
    class. I want to create an override specific for the NTP servers by
    declaring something specific in the node declaration. Something like
    "baseclass::ntp:restrict => true,". Or alternatively, how would I change
    one of the already declared variable from baseclass::ntp?

    Does anyone have any ideas host to do this?

    This is what I have so far:

    templates.pp

    class baseclass {
    include defaultusers
    include sudoers
    include issue

    class { ntp:
    ensure => running,
    servers => ['ntpserver1.host.com',
    'ntpserver2.host.com',],
    autoupdate => false,
    }
    }




    nodes.pp

    node default {
    include baseclass
    }

    node "ntpserver1.host.com" inherits default {
    <some code here to declare new variable in baseclass::ntp>
    <some code here to change existing variable, such as "ensure">
    }
    I don't have any objection to node inheritance, though I do recommend
    keeping node inheritance trees very shallow -- two levels, preferably, or
    three as an absolute, special-case maximum. You also need to understand
    what it means. Specifically, it really does mean NODE inheritance. The
    inheriting node does not get the inherited node's declarations directly,
    but rather the whole node, with its own, separate scope. The inherited
    node's declarations will be parsed and interpreted independently of any
    inheriting nodes that may be in play. Inheriting nodes can only add their
    own declarations on top.

    There is a syntax for resource parameter override, but it does not work for
    classes (and though there are efforts underway to improve that, it *cannot*work for classes under some circumstances). Your inheriting node therefore
    cannot operate as you hoped. The best solution is probably for your class
    to draw its data from hiera, so that you can use your hiera hierarchy to
    provide different parameters in the first place based on the nature of the
    client being configured.

    Alternatively, the old-school way to do this is to use class inheritance.
    In fact, it is precisely what class inheritance is meant for. The
    inheritance approach would involve creating a subclass of ntp, say
    ntp::server, which applies appropriate overrides to the parameters of
    resources declared by its parent class. You then declare the subclass
    (also or instead) to the nodes that should be NTP servers. Consult the
    language docs for details.


    John

    --
    You received this message because you are subscribed to the Google Groups "Puppet Users" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users+unsubscribe@googlegroups.com.
    To post to this group, send email to puppet-users@googlegroups.com.
    Visit this group at http://groups.google.com/group/puppet-users?hl=en.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Sergio Jimenez at Mar 26, 2013 at 3:31 pm
    Not really sure about it (pretty new in puppet) but ... what about
    parametrized classes? You could define default values for parameters in the
    class or overwrite them when using the class.


    sjr.
    On Tuesday, March 26, 2013 3:14:51 AM UTC+1, Cesar Covarrubias wrote:

    I am trying to create a "template" for all my servers. I have 2
    configurations. An NTP client (which is taken care of in the baseclass
    class. I want to create an override specific for the NTP servers by
    declaring something specific in the node declaration. Something like
    "baseclass::ntp:restrict => true,". Or alternatively, how would I change
    one of the already declared variable from baseclass::ntp?

    Does anyone have any ideas host to do this?

    This is what I have so far:

    templates.pp

    class baseclass {
    include defaultusers
    include sudoers
    include issue

    class { ntp:
    ensure => running,
    servers => ['ntpserver1.host.com',
    'ntpserver2.host.com',],
    autoupdate => false,
    }
    }




    nodes.pp

    node default {
    include baseclass
    }

    node "ntpserver1.host.com" inherits default {
    <some code here to declare new variable in baseclass::ntp>
    <some code here to change existing variable, such as "ensure">
    }
    --
    You received this message because you are subscribed to the Google Groups "Puppet Users" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users+unsubscribe@googlegroups.com.
    To post to this group, send email to puppet-users@googlegroups.com.
    Visit this group at http://groups.google.com/group/puppet-users?hl=en.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Jcbollinger at Mar 27, 2013 at 1:04 pm

    On Tuesday, March 26, 2013 7:02:34 AM UTC-5, Sergio Jimenez wrote:

    Not really sure about it (pretty new in puppet) but ... what about
    parametrized classes? You could define default values for parameters in the
    class or overwrite them when using the class.
    If you look at his code, you will see that he is already using a
    parameterized class. His question is about overriding parameter values he
    has already declared for that class.

    Speaking of parameterized classes, by the way, they should not be used as
    base classes in class inheritance, so converting to an old-school approach
    based on class inheritance would require changing the parameterized class
    to a normal one. Not much of a loss, really, but just saying.


    John

    --
    You received this message because you are subscribed to the Google Groups "Puppet Users" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users+unsubscribe@googlegroups.com.
    To post to this group, send email to puppet-users@googlegroups.com.
    Visit this group at http://groups.google.com/group/puppet-users?hl=en.
    For more options, visit https://groups.google.com/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppuppet-users @
categoriespuppet
postedMar 26, '13 at 9:55a
activeMar 27, '13 at 1:04p
posts5
users4
websitepuppetlabs.com

People

Translate

site design / logo © 2022 Grokbase