我有一个琐碎的木偶2.7.18安装如下:
=== manifests/site.pp === node build-1 { include mod1 include mod2 include mod3 } === modules/mod1/manifests/init.pp === import "*" === modules/mod1/manifests/mod1.pp === class mod1 { file { "/tmp/mod1.file": ensure => present } } === modules/mod2/manifests/init.pp === import "*" === modules/mod2/manifests/mod2.pp === class mod2 { file { "/tmp/mod2.file": ensure => present } } === modules/mod3/manifests/init.pp === import "*" === modules/mod3/manifests/mod3.pp === class mod3 { file { "/tmp/mod3.file": ensure => present } }
当我尝试运行build-1主机上的puppet代理时,我收到以下消息:
: 0 build-1; sudo puppet agent --noop --test err: Could not retrieve catalog from remote server: Error 400 on SERVER: Could not find class mod1 for build-1 at /etc/puppet/manifests/site.pp:2 on node build-1 warning: Not using cache on failed catalog err: Could not retrieve catalog; skipping run
如果我再次运行它,我得到相同的消息,但类mod2。 运行它第三次给我类mod3的消息。 最后,第四次运行它的作品。 但是,如果我除了触摸其中一个模块文件(例如,mod1.pp)之外什么也不做,那么我必须再次完成整个事情。 运行木偶代理,直到每个模块重新编译正确。 这显然是不可持续的。
我注意到的其他一些事情:
是否有任何理由你不能在init.pp文件中的主类的定义?
我对类发现的理解是基本的,但是对于mod1::mod1类而不是mod1::mod1类,将自动检查文件modules/mod1/mod1.pp
据我所知, mod1类应该始终在init.pp定义,但这并不意味着你的整个模块的configuration必须在那里 – 子类是有帮助的!
我相信这些天推荐的模块devise是这样的:
mod1/init.pp :
class mod1 { include mod1::install include mod1::config include mod1::service }
mod1/install.pp :
class mod1::install { package { "somepackage": ensure => installed, } }
mod1/config.pp :
class mod1::config { file { "/etc/someapp.conf": content => "foo", require => Class["mod1::install"], notify => Class["mod1::service"], } }
mod1/service.pp :
class mod1::service { service { "someapp": ensure => running, } }
编辑:进一步,你不应该在模块中使用import :
http://docs.puppetlabs.com/puppet/2.7/reference/lang_import.html
自动载入清单中的导入行为是未定义的,并且可能会在次要版本的Puppet之间随机变化。 你不应该在模块中放入import语句; 他们应该只存在于site.pp.