Chef - Returning a variable from a powershell script

I would like to know if there is a way to return the value of a variable from the powershell script defined in powershell_scriptresource?

My resource is powershellas follows:

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

I would like to use the return value testfrom the script for use in other resources based on if conditions.

thanks

+4
source share
2 answers

Ohai!

I think you really want to use the PowershellOutMixin found here in the Powershell cookbook .

Chef’s resources rarely return, but why do you need heavy resources!

powershell, :

include Chef::Mixin::PowershellOut
cmd = powershell_out!('command')
cmd.stdout #=> ...
cmd.stderr #=> ...
+5

, Mixlib, powershell script. :

# get the result object (and exit code) from the code execution:           
result = Mixlibrary::Core::Shell.windows_script_out(:powershell, mycode)
exit_status = result.exitstatus

@carpNick open-source , .... powershell, (bash, win modules ...) - .

, . , - , . , , .

... @carpnick | https://github.com/carpnick

0

All Articles