[英]Puppet conditional only if file exists in a particular directory
我的人偶清單中有以下文件資源:
file{
'example.dat'
path => "/path/to/example.dat",
owner => devops,
mode => "0644",
source => "/path/to/example.txt"
}
我只想在.txt
文件存在於特定目錄中時運行上述代碼段。 否則,我不希望該代碼段運行。
我如何在木偶中做到這一點?
通常,您會創建一個自定義事實,當相關目錄滿足您的條件時返回 true。 例如:
Facter.add('contains_txt') do
setcode do
! Dir.glob("/path/to/dir/*.txt").empty?
end
end
然后你會寫:
if $facts['contains_txt'] {
file { 'example.dat':
path => "/path/to/example.dat",
owner => devops,
mode => "0644",
source => "/path/to/example.txt",
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.