我希望在文件内容没有变化时跳过某些exec和文件资源。它的文件和服务组合...... 例如,
file { 'configfile.cfg':
ensure => file,
path => '/etc/configfile.cfg',
mode => '0644',
owner => 'root',
group => 'root',
content => template($template_file),
require => Package[$main_package],
notify => Service[$service],
}
service { $service:
ensure => $ensure,
enable => $enable,
hasrestart => true,
hasstatus => true,
require => [ Package[$main_package], File['configfile.cfg'] ],
}
上面的代码按预期工作。仅当服务检测到/etc/configfile.cfg中的任何更改时,服务才会重新启动。
但我对文件和exec组合遵循相同的方法,但它不起作用....请看下面的代码
exec { 'purge-config-files':
before => [File["${config_file_service}"], File["${config_file_host}"]],
command => "/bin/rm -f ${baseconfigdir}/*",
notify => Domain_ip_map[$domain_ip_map_titles],
}
file { 'deployconfig.cfg':
ensure => file,
path => '/home/path/deployconfig.cfg',
mode => '0644',
owner => 'root',
group => 'root',
content => "test",
notify => Exec['purge-config-files'],
}
此代码未按预期工作。即使没有变化 /home/path/deployconfig.cfg,执行[' purge-config-files']总是 执行......这可能是什么原因?
答案 0 :(得分:1)
我找到了答案
exec { 'purge-config-files':
before => [File["${config_file_service}"], File["${config_file_host}"]],
command => "/bin/rm -f ${baseconfigdir}/*",
notify => Domain_ip_map[$domain_ip_map_titles],
subscribe=> File['deployconfig.cfg'],
refreshonly => true,
}
我忘记了订阅和刷新
...