puppet排除模块

puppet排除模块

我已经为 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',
        }
}

在 nodes.pp 上,我将此类包含到所有服务器中,对于其中一个服务器,我想包含此类但排除syslog::base

知道如何做吗?

答案1

尝试这个:

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

对于您想要排除的服务器syslog::base

node 'special' {
    include centos_base::no_syslog_base
}

对于所有其他服务器:

node 'normal' {
    include centos_base
}

答案2

将其变成定义并指定描述原因为什么要排除该类——可能是因为它是一个虚拟机,或者一个暂存环境,或者其他什么。

答案3

我喜欢通过让类足够智能来了解它不应该在哪里运行来解决这类问题。例如,我有一个类应该只在具有 SSD 的机器上运行;与其做大量的前期工作来定义这些机器并构建条件类,或者创建一组特定的类来包含每个命名主机,我编写了一个自定义 Facter 事实来确定机器是否安装了 SSD(检查/sys/block/sd*/queue/rotational)。然后我将类写为“if ($has_ssd) {...”。这样,我可以在任何机器上包含它,并且它只会在应该运行时运行。

相关内容