我有一个像这样的默认节点:
node default { include test_server # A bunch of other irrlevant includes }
然后我有一个像这样的节点规范:
node linus inherit default { include production_server }
我想取消包含test_server和production_server因为它们是互斥的。
我如何做到这一点?
你最好做一个名为“servertype”的类,并根据参数进行区分。
class servertype($testing = false) { if ($testing) { ... resources from your testing class ... } else { ... resources from your production class ... } }
一般来说,使用ENC (外部节点分类器)是将类应用于主机的最佳select,而不是节点文件。 您可以创build“主机组”,其中每个组有多个类。 这样可以避免inheritance。 有几个ENC可用,所以你不必创build自己的。
Puppet中没有“uninclude”的概念, 一旦你包括了一些东西,就包括在内了。 你可以做的最好的做法是让一个包含内部调用的类包含test_server或production_server ,具体情况取决于环境(查看事实,查看传入的variables等)。
除此之外,如果包含两个类别,则可能会导致错误。 一个简单的方法就是简单地在每个类中包含一个哨兵资源,在这两个地方资源的名字是相同的:
notice { unused: loglevel => debug, }
试图包含这两个类将导致编译器失败,从而阻止编译目录。
另一个select是使用每个类中defined函数来testing是否已经定义了另一个类。 如果是这样, fail :
if defined(Class["test_server"]) { fail "Can't include test_server and production_server at the same time" }
defined有一些特殊的语义,虽然,因为它是依赖于秩序,木偶并没有真正提供了parsing/评估sorting方面的许多保证。