I want to use powershell script in only_if and not_if in one of my resource. Please help me in using that.
PowerShell script is the default guard interpreter for the powershell_script resource. If you want to use it with other resources add the following to your resource:
guard_interpreter :powershell_script
Then you can follow the same guidance for using Guards in the powershell_script resource as per https://docs.chef.io/resource_reference.html#id565
Contrived example:
your_resource 'your_resource_name' do
a_resource_property 'first'
guard_interpreter :powershell_script
not_if 'Test-Path c:\' # will return $True
end
@stuartpreston
I want to use a multi-line script like file.ps1 which will return true or false. I want to evaluate based on that.
your_resource 'your_resource_name' do
a_resource_property 'first'
guard_interpreter :powershell_script
not_if file.ps1
end
Having a multi-line script as a guard is usually a "smell" that you might be able to break down the work a bit more into multiple resources within your recipe. But if you must then you can use the powershell_out Ruby mixin to achieve this, example:
test.ps1:
($true -eq $true)
recipe.rb:
log 'testing' do
not_if { powershell_out('test.ps1') }
end