Say I've got two blocks like this:
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'
}
}
}
I built a test that does something like this, but it seems like the Service resource gets executed regardless of the File resource's test output - that is, if it actually did anything to the file.
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.
Contrived example aside, how can I only have the Script resource execute only if the File resource actually did something?
My use case here is checking to see if a file has changed in a remote location, and if so, copy it to the local machine, then restart a service. I obviously don't want to restart the service if the file hasn't changed, but I can't see a good idempotent way to do that, since the file is being tested using a hash - I'd have to have my service restart step do the same file hash check.