On 3/7/2011 6:38 AM, jcbollinger wrote:

On Mar 5, 5:22 pm, "."<f...@kraptastic.com>  wrote:
      I'm trying to find out the 'puppet' way of overwriting a
config/variable. I've tried using a define
(http://pastebin.com/ncVwtwGj) and a parameterized class
(http://pastebin.com/3UysCgi7). But both end up with duplicate definitions.

      I'm trying to avoid setting up global variables or having a
boatload of if statements in the class itself.

      Basically I want to inherit a node and overwrite what is unique
about the particular server. Is this possible?
Yes.  This is exactly what subclassing is for.  For example:

node 'webservers' {
     include "sudoers::webserver"
}

node 'web01' inherits 'webservers' {
    include "sudoers::webserver::web01"
}

class sudoers::install {
    package { "sudo":
       ensure  =>  installed,
    }
}

class sudoers::webservers {
    # NOT a subclass of sudoers::install
    include "sudoers::install"

    file { "/etc/sudoers":
       ensure   =>  file,
       owner   =>  root,
       group    =>  root,
       mode     =>  440,
       source   =>  "puppet:///common/etc/sudoers",
       # Personal preference: depend on specific
       # resources, not classes
       require  =>  Package["sudo"],
    }
}

class sudoers::webservers::web01
       inherits sudoers::webservers {

    # Override a property of an inherited resource
    File["/etc/sudoers"] {
       source   =>  "puppet:///web/etc/sudoers.web01",
    }
}

===

You can use parameterized classes to similar effect, but then you must
ensure that the parameterized class is included at most once
(regardless of the parameter list) for any node; this is a significant
present limitation of parameterized classes relative to traditional
ones.

You can also use defines to similar effect, but you must not invoke
the same definition twice with the same name for the same node.

Moreover, no matter what, you can *never* include multiple
declarations of the same resource.  Even in the example above, the
subclass does not provide a separate declaration for the sudoers file;
it just overrides properties of the resource declared by its
superclass.  Only subclasses can do that, and subclasses should be
created only for that purpose.

Note also that node inheritance is a different beast from class
inheritance.  The two can work together as shown above, but either can
also be used on its own.  Node inheritance is not related to resource
property overriding.


John


Thank you very much, this is exactly what I was looking for.

--
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+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/puppet-users?hl=en.

Reply via email to