我附上了工头的报告截图,下面粘贴的是我遇到问题的课程。
如果难以查看整个代码,我会突出显示Exec
部分未按预期运行
exec { $service:
path => ["/usr/bin/","/usr/sbin/","/bin"],
subscribe => Domain_ip_map[$domain_ip_map_titles],
command => "sudo service nagios restart",
}
上述Exec[$service]
订阅Domain_ip_map[...]
,Exec['purge-config-files']
通知require => File['deployconfig.cfg']
。
由于deployconfig.cfg
文件没有变化,File['deployconfig.cfg']
没有运行,因此没有通知,因此Exec['purge-config-files']
和自定义Domain_ip_map
资源不会跑。到目前为止,一切都按预期工作。但是最后一部分Exec[$service]
订阅了Domain_ip_map
。
Domain_ip_map
未运行时,Exec[$service]
如何执行 成功吗?
class testclass ( $data = {
item1 => {
domain => 'testdomain.com',
ipaddress => '1.1.1.1',
},
},
$baseconfigdir = '/usr/local/servers',
$config_file_host = '/usr/local/test.cfg',
$config_file_service = '/usr/local/test_service.cfg' ) {
validate_hash($data)
$domain_ip_map_titles = keys($data)
file { "${baseconfigdir}":
ensure => directory,
}
exec { 'purge-config-files':
command => "/bin/rm -f ${baseconfigdir}/*",
notify => Domain_ip_map[$domain_ip_map_titles],
require => File['deployconfig.cfg'],
refreshonly => true,
}
file { 'deployconfig.cfg':
ensure => file,
path => '/home/deployconfig.cfg',
mode => '0644',
owner => 'root',
group => 'root',
content => "test",
notify => Exec['purge-config-files'],
}
#problem here, its subscribed to Domain_ip_map, but even if Domain_ip_map doesn't run, Exec['$service'] always execute, how???
exec { $service:
path => ["/usr/bin/","/usr/sbin/","/bin"],
subscribe => Domain_ip_map[$domain_ip_map_titles],
command => "sudo service nagios restart",
}
create_resources(domain_ip_map, $data)
}
define domain_ip_map($domain, $ipaddress) {
nagios_host { $domain:
....
}
nagios_service { "check_ping_${domain}":
....
}
}