說我有兩大塊這樣的:如何根據以前的資源執行情況有條件地執行Powershell DSC中的資源?
Configuration TestConfig
{
Node ('localhost') {
File foo {
DestinationPath = 'C:\foo.txt'
Contents = 'Bar'
}
Script dothing {
SetScript = {'Baz' | set-content C:\foo.txt}
TestScript = {return $false}
GetScript = {
return @{
GetScript = ''
SetScript = ''
TestScript = ''
Credential = $Credential
Result = (Invoke-Expression -Command $TestScript)
}
}
DependsOn = '[File]foo'
}
}
}
我建了一個試驗,做這樣的事情,但它似乎像服務資源獲取文件資源的測試輸出,無論執行的 - 也就是說,如果它實際上對文件做了任何事情。
VERBOSE: [MACHINENAME]: LCM: [ Start Set ]
VERBOSE: [MACHINENAME]: LCM: [ Start Resource ] [[File]foo]
VERBOSE: [MACHINENAME]: LCM: [ Start Test ] [[File]foo]
VERBOSE: [MACHINENAME]: [[File]foo] The destination object was found and no action is required.
VERBOSE: [MACHINENAME]: LCM: [ End Test ] [[File]foo] in 0.0040 seconds.
VERBOSE: [MACHINENAME]: LCM: [ Skip Set ] [[File]foo]
VERBOSE: [MACHINENAME]: LCM: [ End Resource ] [[File]foo]
VERBOSE: [MACHINENAME]: LCM: [ Start Resource ] [[Script]dothing]
VERBOSE: [MACHINENAME]: LCM: [ Start Test ] [[Script]dothing]
VERBOSE: [MACHINENAME]: LCM: [ End Test ] [[Script]dothing] in 0.0050 seconds.
VERBOSE: [MACHINENAME]: LCM: [ Start Set ] [[Script]dothing]
VERBOSE: [MACHINENAME]: LCM: [ End Set ] [[Script]dothing] in 0.0060 seconds.
VERBOSE: [MACHINENAME]: LCM: [ End Resource ] [[Script]dothing]
VERBOSE: [MACHINENAME]: LCM: [ End Set ]
VERBOSE: [MACHINENAME]: LCM: [ End Set ] in 0.0390 seconds.
人爲的例子不談,我怎麼能只擁有腳本資源執行只有當文件資源實際上做了什麼?
我在這裏的用例是檢查一個文件是否在遠程位置發生了變化,如果是,將它複製到本地機器,然後重新啓動服務。如果文件沒有改變,我顯然不想重新啓動服務,但是我看不到一個好的冪等方法來做到這一點,因爲文件正在使用散列測試 - 我必須有我的服務重新啓動步驟執行相同的文件散列檢查。
同意;沒有本地的方式來有條件地執行基於另一資源的資源。 – briantist 2014-09-29 22:15:39