Ask Your Question
0

Get powershell value in puppet

asked 2013-03-14 18:59:30 -0500

kevin gravatar image

My powershell returns 1 or 0

if ($mebName -contains $userName){ write-host 1 exit 1 }else{ write-host 0 exit 0 }

how do i consume this value returned from powershell in my puppet manifest? ideally i want this value to be stored in puppet variable so i can use that variable to call a puppet class based on the condition.

edit retag flag offensive close merge delete

Comments

Where does $mebName come from? I can't tell from the question if you should be writing a custom fact with a powershell helper, or converting the logic above into ...(more)

jsweeny gravatar imagejsweeny ( 2013-03-15 08:24:52 -0500 )edit

4 Answers

Sort by ยป oldest newest most voted
1

answered 2013-03-17 20:48:29 -0500

reidmv gravatar image

Create a Custom Fact.

http://docs.puppetlabs.com/guides/custom_facts.html

Perhaps something like:

Facter.add("mebname_contains_username") do
  confine :osfamily => "windows"
  setcode do
    powershell = 'C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe'
    command = 'if ($mebName -contains $userName){ write-host 1; exit 1 }else{ write-host 0; exit 0 }'
    Facter::Util::Resolution.exec(%Q{#{powershell} -command "#{command}"})
  end
end

For an in-depth walkthrough of everything involved in writing and using custom facts, check out http://info.puppetlabs.com/webinars.html and search for Kelsey Hightower's "Facter 101" tutorial.

edit flag offensive delete link more
0

answered 2013-03-18 08:21:01 -0500

Michael Thompson gravatar image

updated 2013-03-18 08:21:33 -0500

Use the PS -Command flag...

exec { "java790x64native-get-zip": command => 'C:/Windows/System32/WindowsPowerShell/v1.0/powershell.exe -executionpolicy remotesigned -Command C:/Path/To/Script/script.ps1 }

edit flag offensive delete link more
0

answered 2013-03-15 08:09:46 -0500

llowder gravatar image

You can't, directly - there are things like generate() but all functions run on the master, and I am assuming you need this to run on the agent node.

If you can put that into a custom fact, and then reference that as a variable during your puppet runs, which may be the best option.

edit flag offensive delete link more
0

answered 2013-03-16 10:03:48 -0500

Have you tried the powershell provider for the exec resource found on the Forge?

While you can't exactly accomplish what you've asked, you can use resource ordering to make other resources in your class rely on the powershell provided exec resource.

This resource will interpret the error code returned by powershell and use that to determine whether or not things were successful. If it was not successful, resources that depend on your exec resource will not be managed while the inverse is true if the exec was successful. This should give you some flow control and error handling ... (more)

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2013-03-14 18:59:30 -0500

Seen: 2,111 times

Last updated: Mar 18 '13