Puppetlabs文档声明,为了使一个类需要另一个类,您应该使用关系链接语法,并在外部节点中声明两个类。
我有一个repo类,它创建了yum定义,每个modole中的许多包都依赖这个定义。在每个模块中,我都有一个类‘’repo‘、->类’‘modulename’语句,这两个类都在节点中声明。但是,当木偶运行时,它并不总是按照预期在模块类之前执行repo类。为什么不行?下面的例子(傀儡2.6.16):
编辑:这个问题有三个基本的解决方案。
那么,考虑到木偶v3和将重构降到最低的愿望,这些方法中哪一种是最好的呢?
舱单puppettest.pp
class { 'repo': }
class { 'maradns': }
class repo {
class { 'repo::custom': }
}
class repo::custom {
yumrepo {'custom':
enabled => 1,
gpgcheck => 0,
descr => "Local respository - ${::architecture}",
baseurl => 'http://repo.nike.local/CentOS/\$releasever/\$basearch';
}
}
class maradns {
Class['repo'] -> Class['maradns::install']
Class['maradns::install'] -> Class['maradns::config']
Class['maradns::config'] ~> Class['maradns::service']
class { 'maradns::install': }
class { 'maradns::config': }
class { 'maradns::service': }
}
class maradns::install {
package { 'maradns':
ensure => present,
}
}
class maradns::config {
file { 'mararc':
ensure => present,
path => '/etc/mararc',
mode => '0644',
owner => root,
group => root,
}
}
class maradns::service {
service { 'maradns':
ensure => running,
enable => true,
hasrestart => true,
}
}输出:
puppet apply puppettest.pp
err: /Stage[main]/Maradns::Install/Package[maradns]/ensure: change from absent to present failed: Execution of '/usr/bin/yum -d 0 -e 0 -y install maradns' returned 1: Error: Nothing to do
notice: /Stage[main]/Maradns::Config/File[mararc]: Dependency Package[maradns] has failures: true
warning: /Stage[main]/Maradns::Config/File[mararc]: Skipping because of failed dependencies
notice: /Stage[main]/Maradns::Service/Service[maradns]: Dependency Package[maradns] has failures: true
warning: /Stage[main]/Maradns::Service/Service[maradns]: Skipping because of failed dependencies
notice: /Stage[main]/Repo::Custom/Yumrepo[custom]/descr: descr changed '' to 'Local respository - x86_64'
notice: /Stage[main]/Repo::Custom/Yumrepo[custom]/baseurl: baseurl changed '' to 'http://repo.test.com/CentOS/\$releasever/\$basearch'
notice: /Stage[main]/Repo::Custom/Yumrepo[custom]/enabled: enabled changed '' to '1'
notice: /Stage[main]/Repo::Custom/Yumrepo[custom]/gpgcheck: gpgcheck changed '' to '0'
notice: Finished catalog run in 2.15 seconds发布于 2012-07-30 11:27:01
通过在回购中包含repo::定制,而不是直接依赖于repo::定制,您得到了什么?
在类中声明类的模式也可能会为重复的定义设置。如果可能的话,我将专注于直接使用repo::定制。
https://stackoverflow.com/questions/11675102
复制相似问题