2

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

3 Answers 3

3

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
}
2

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.

1
  • any example on how to do this???
    – krisdigitx
    Sep 29, 2011 at 10:08
0

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .