Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chef - Returning a variable from powershell script

I would like to know if there is a way to return a variable value from a powershell script defined in powershell_script resource?

My powershell resource looks like following:

powershell_script "Test Script" do
  code <<-EOH
    Write-Host "Hello World!"
   return "test"
  EOH
end

I would like to use the returned value test from the script to use in other resources based on if conditions.

Thanks

like image 992
user3140243 Avatar asked Dec 27 '13 18:12

user3140243


1 Answers

Ohai!

I think you actually want to use the PowershellOut Mixin found here in the Powershell cookbook.

Chef resources rarely return values, but that's what heavy-weight resources are for!

If you have the powershell cookbook, you can do this:

include Chef::Mixin::PowershellOut
cmd = powershell_out!('command')
cmd.stdout #=> ...
cmd.stderr #=> ...
like image 151
sethvargo Avatar answered Sep 30 '22 07:09

sethvargo