Chef - Powershell Edition

I recently upgraded to Windows 10, and I notice a very strange / annoying problem when executing knife commands.

When I ran this in 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 written to and stored in the $nodes variable. When I run the same command from PowerShell ISE, it functions as expected, where the values ​​of $nodes contain my list node.

I tried several options, 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 happens when my powershell console session cannot capture the output from the ruby ​​interpreter, but the 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 

I tried with and without the chef's powerhell module: Import-Module Chef the 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 do this, 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 fine in powershell, returning a list of nodes that have not registered in the last 14 days. When I run it in ISE, it does not return a single node (although I know that there are at least 10 that meet these criteria).

+5
source share
1 answer

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

 Remove-Module chef 

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

+1
source

Source: https://habr.com/ru/post/1246476/


All Articles