Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chef - Powershell Output

I upgraded to Windows 10 recently and I'm noticing a very strange/annoying issue when running knife commands.

When I run this in the powershell console:

$nodes = knife node list

The value of $nodes is $null and all of my nodes are listed in the console window instead of being captured and stored in the $nodes variable. When I run that same command from Powershell ISE, it functions as expected where the values of $nodes contains my node list.

I've tried several variations, all with the same result...

$nodes = & knife node list
$nodes = Invoke-Expression -Command 'knife node list'
$nodes = $(Invoke-Expression -Command 'knife node list')
$nodes = & knife node list 2>&1
$nodes = & knife node list 3>&1
$nodes = & knife node list 4>&1

What is going on where my powershell console session cannot capture the output from the ruby interpreter but powershell ise session can!?

Name                           Value
----                           -----
PSVersion                      5.0.10586.122
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.10586.122
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Tried with and without the chef powershell module: Import-Module Chef same result.

PS C:\Users\nhudacin> chef -v
Chef Development Kit Version: 0.12.0
chef-client version: 12.8.1
berks version: 4.3.0
kitchen version: 1.6.0

Now here's the kicker... I would just use ISE to get it done, but this command:

$nodes = knife exec -E 'b = Time.now.to_i;a = (b - (336*60*60)).to_i;printf "%-40s %-23s\n", "Name", "Last Check-In";search(:node, "ohai_time:[0 TO #{a}]") { |n| checkIn = Time.at(n["ohai_time"]).strftime("%F %R"); printf "%-40s %-23s\n", n.name, checkIn;}'

works perfectly in powershell console, returning a list of nodes that hasn't checked-in within the last 14 days. When I run it in ISE, it doesn't return a single node (even though I know there are at least 10 that meet this criteria).

like image 220
Nick H. Avatar asked Apr 05 '16 14:04

Nick H.


1 Answers

Try removing the chef module that is installed as part of the ChefDK. That is what fixed this problem for me.

Remove-Module chef

https://github.com/chef/chef/issues/4045

like image 91
Brandon Olin Avatar answered Oct 09 '22 05:10

Brandon Olin