i have created a base class for all the servers in puppet,

class centos_base {
        include chkconfig
        include hosts
        include inittab
        include nscd
        include nsswitch
        include ntp
        include puppet
        include syslog::base
        include ssh
#        include curp
        include security
        include sysctl
        include sudo
        include users
        include vim
        include yum
        include rpmforge
#       include vmware-tools

        import 'resolver'

        resolv_conf { default_resolver:
                domainname  => "domain.com",
                searchpath  => ['domain.com'],
                nameservers => ['x.x.x.y', 'x.x.y.y' ],
  }

        import 'nrpe'

        nrpe_conf { nrpe:
                                listen_address => $ipaddress,
                                nagios_address => 'xx.xx.xx.yy',
        }
}

and on nodes.pp, i include this class for all servers, for one of the server,i want to include this class but exclude syslog::base.

any idea how this can be done..

link|improve this question

45% accept rate
feedback

3 Answers

up vote 3 down vote accepted

Try this:

class centos_base {
    define includer($exclude=false) {
        if !$exclude {
            include $name
        }
    }

    includer{ ["chkconfig", "hosts", ...: }

    class no_syslog_base inherits centos_base {
        Includer["syslog::base"] { exclude => true }
    }
    ...
}

For server you want to exclude syslog::base:

node 'special' {
    include centos_base::no_syslog_base
}

and for all other servers:

node 'normal' {
    include centos_base
}
link|improve this answer
feedback

Turn it into a define and specify a parameter that describes the reason why you want to exclude that class -- it might be because it's a VM, or a staging environment, or whatever.

link|improve this answer
any example on how to do this??? – krisdigitx Sep 29 '11 at 10:08
feedback

The way I like to solve this sort of problem is by making the class smart enough to know where it should not be run. For example, I have a class that should be run only on machines that have an SSD; rather than doing a lot of up-front work to define which machines those were and build conditional classes, or create a specific set of classes to include for each named host, I wrote a custom Facter fact to determine whether the machine had an SSD installed (inspecting /sys/block/sd*/queue/rotational). Then I wrote the class as "if ($has_ssd) {...". That way, I can include it on any machine, and it will only run if it's supposed to run.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.