apache2 をインストールして ssl を構成し、apache サービスを開始する 1 つの apache クラスを作成しました。1 つの仮想ホストを構成し、Apache サービスを再起動する 1 つのサブクラスを作成しています。仮想ホストが追加された後に apache2 サービスに通知しようとすると、循環依存エラーが発生します。
require を include に変更することでこのエラーを解決しましたが、これは apache クラスのリソースが apache::no の前に実行されることを意味しますか?
そうでない場合、この依存関係エラーを解決する方法は何ですか?
別のクラスのリソースに通知することは良い習慣ですか?
Error: Failed to apply catalog: Found 1 dependency cycle:
(Exec[no] => Service[apache2] => Class[Apache] => Class[Apache::No] => Exec[no])
Try the '--graph' option and opening the resulting '.dot' file in OmniGraffle or GraphViz
apache.pp
class apache {
$listen_port="8181"
$no_port="4143"
#file { '/etc/apache2/ports.conf' :
#ensure => present ,
#content => template("apache/ports.conf.erb"),
#require => Package['apache2'],
#notify => Service['apache2'],
#}->
case $facts['osfamily'] {
/^(Debian|Ubuntu)$/: {
file { '/etc/apache2/sites-available/000-default.conf' :
ensure => present ,
content => template("apache/000-default.conf.erb"),
require => Package['apache2'],
notify => Service['apache2'],
noop => true,
}
file { '/etc/apache2/sites-available/default-ssl.conf':
ensure => present ,
content => template("apache/default-ssl.conf.erb"),
require => Package['apache2'],
notify => Service['apache2'],
#noop => true,
}
file { ['/etc','/etc/apache2','/etc/apache2/ssl'] :
ensure => directory,
require => Package['apache2'],
}
package { 'apache2' :
ensure => latest,
notify => Exec['ssl']
} ->
augeas { 'no' :
context => "/files/etc/apache2/ports.conf",
changes => [
"set /files/etc/apache2/sites-available/default-ssl.conf/IfModule/VirtualHost/directive[2]/arg localhost",
"set /files/etc/apache2/sites-available/default-ssl.conf/IfModule/VirtualHost/directive[8]/arg /etc/apache2/ssl/apache.key",
"set /files/etc/apache2/sites-available/default-ssl.conf/IfModule/VirtualHost/directive[7]/arg /etc/apache2/ssl/apache.crt",
"set /files/etc/apache2/ports.conf/IfModule[2]/directive/arg $$no_port",
"set /files/etc/apache2/ports.conf/IfModule[1]/directive/arg $no_port",
"set /files/etc/apache2/ports.conf/directive/arg 8181",
"set /files/etc/apache2/sites-available/000-default.conf/VirtualHost/arg *:8181",
"set /files/etc/apache2/sites-available/default-ssl.conf/IfModule/VirtualHost/arg *:$no_port",
],
require => Package['apache2'],
} ->
service { 'apache2' :
ensure => running
}
package { 'openssl' :
ensure => latest
} ->
exec { 'ssl' :
path => ["/usr/local/sbin","/usr/local/bin","/usr/sbin","/usr/bin","/sbin","/bin"],
command => 'openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/apache2/ssl/apache.key -out /etc/apache2/ssl/apache.crt -subj "/C=GB/ST=London/L=London/O=Global Security/OU=IT Department/CN=example.com" ; a2enmod ssl ; a2ensite default-ssl ',
notify => Service['apache2'],
require => Augeas['no'],
refreshonly => true,
}
}
}
No.pp
class apache::no {
require ::apache
$listen_port="8181"
file { 'no' :
ensure => present,
path => '/etc/apache2/sites-available/no.conf',
content => template("apache/no.conf.erb"),
notify => Exec['no'],
}
Exec { 'no' :
path => ["/usr/local/sbin","/usr/local/bin","/sbin","/bin","/usr/sbin","/usr/bin","/root/bin"],
command => 'a2ensite no.conf',
notify => Service['apache2'],
refreshonly => true,
}
#Service { 'apache2' :
#ensure => running,
#}
}
ありがとう