Puppet Exec 资源仅在文件更改时应用

Puppet Exec resource to apply only when a File changes

我有两个 Puppet 资源类型,一个 File 和一个 Exec:

file { 'folder_a':
  source  => 'puppet:///modules/folder_a',
  ensure  => 'directory',
  recurse => true,
  path    => 'C:/folder_a',
  source_permissions => ignore,
  notify  => Exec['install.bat'],
}

exec { 'test_cmd':
  path      => $::path,
  command   => 'cmd.exe /c C:/test.cmd',
  provider  => windows,
  subscribe => File['folder_a'],
  logoutput => true,
}

如果文件资源不适用,我也不希望执行资源运行。但是如果源文件更新了,那么Exec应该运行.

这可能吗?

是的。正如 Exec 类型的 docs 中所述,有 refreshonly 属性:

refreshonly

The command should only be run as a refresh mechanism for when a dependent object is changed.

听起来这正是您所需要的:

exec { 'test_cmd':
  path      => $::path,
  command   => 'cmd.exe /c C:/test.cmd',
  provider  => windows,
  subscribe => File['folder_a'],
  logoutput => true,
  refreshonly => true, # Add this line.
} 

请记住,some 强烈建议 refreshonly 仅作为最后的手段使用。