我正在研究一个相当大而复杂的木偶模块,我遇到了一个问题,即声明对类的依赖不会转换为对该类中定义的类资源的依赖。我创建了一个例子。
node default {
notify {'This is my notification':
require => Class['big_class'],
}
class {'big_class':}
}
class big_class {
notify {'This is my big class':}
class {'little_class':}
}
class little_class{
notify {'This is my little class':}
class {'smallest_class':}
}
class smallest_class {
notify {'This is my smallest class':}
}
在通知之前,我希望的行为是针对最小,最小和最大的解决方案。但是Puppet不会这样工作。运行结果如下:
Notice: This is my little class
Notice: /Stage[main]/Little_class/Notify[This is my little class]/message: defined 'message' as 'This is my little class'
Notice: This is my big class
Notice: /Stage[main]/Big_class/Notify[This is my big class]/message: defined 'message' as 'This is my big class'
Notice: This is my notification
Notice: /Stage[main]//Node[default]/Notify[This is my notification]/message: defined 'message' as 'This is my notification'
Notice: This is my smallest class
Notice: /Stage[main]/Smallest_class/Notify[This is my smallest class]/message: defined 'message' as 'This is my smallest class'
Notice: Finished catalog run in 0.05 seconds
在“这是我的通知”之后解析的最小类,即使它在通知要求内有效定义。处理这种类型的Senario的最佳做法是什么?如果这是期望的行为,是否有办法声明在类中定义的资源是该类的要求? class class_name
内的所有资源都需要有一个元参数before => Class['class_name'],
吗?
编辑:以下结果导致傀儡抱怨依赖周期。
class smallest_class {
notify {'This is my smallest class':
before => Class['smallest_class'],
}
}
答案 0 :(得分:3)
因此,在清单上生成一个点graph,我们可以看到类之间没有实际的依赖关系。
有几种方法可以解决这个问题。