当文件内容没有变化时跳过木偶函数

skip puppet functions when there is no change in file content

我想在文件内容没有变化的情况下跳过某些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 { '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'],
}

This code is not working as expected. Even if there is no change in /home/path/deployconfig.cfg, Exec['purge-config-files'] is always executing... what could be the reason for this?

我找到了答案

 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,
}

I forgot to put subscribe and refreshonly

.....