Puppetlabs のドキュメントには、あるクラスが別のクラスを必要とするようにするには、リレーションシップ チェーン構文を使用し、外部ノードで両方のクラスを宣言する必要があると記載されています。
各モジュールの多くのパッケージが依存する yum リポジトリ定義を作成するリポジトリ クラスがあります。各モジュールには Class['repo'] -> Class['modulename'] ステートメントがあり、両方のクラスがノードで宣言されています。ただし、パペットが実行されると、モジュール クラスの前にリポジトリ クラスが期待どおりに実行されるとは限りません。なぜだめですか?以下の例 (パペット 2.6.16):
編集:この問題には 3 つの基本的な解決策があるようです。
- before/require メタパラメータを使用して、クラスの依存関係をリソースの依存関係に置き換えます (turingmachine の回答に示されているように)。
- 外部クラスの依存関係を削除し、内部クラス間の依存関係を明示的に述べます。
- stdlib モジュールで Puppetlabs が提供するアンカー タイプを使用して、依存するクラスがチェーン構文を使用して外部クラスへの参照を作成できるようにするクラスを含めます。
Puppet 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