簡體   English   中英

Puppet Exec資源僅在文件更改時適用

[英]Puppet Exec resource to apply only when a File changes

我有兩種人偶資源類型,一個文件和一個執行:

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中針對Exec類型所指出的那樣,存在refreshonly屬性:

refreshonly

僅當更改從屬對象時,才應將命令作為刷新機制運行。

聽起來這正是您所需要的:

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

請記住, 有些人強烈建議refreshonlyrefreshonly用作最后的手段。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM