Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

knife winrm command parallelism #348

Closed
nwesoccer opened this issue Feb 5, 2016 · 14 comments
Closed

knife winrm command parallelism #348

nwesoccer opened this issue Feb 5, 2016 · 14 comments

Comments

@nwesoccer
Copy link

I have a command we run in order to run chef-client on all our windows machines in an environment:

knife winrm "chef_environment:?? AND platform:windows" "chef-client" -x ?? -P ??

When using Chefdk 0.9.0 (with knife-windows 0.8.6) this command executes chef-client on all those machine in parallel, so only taking as long as the longest chef-client run. However using Chefdk 0.10.0 (with knife-windows >= 1.0.0) this command executes chef-client one after another, taking much much longer to run.

Am I missing something? Was parallelism in knife wirm removed?

Thanks

@nwesoccer nwesoccer changed the title Chef-client run parallelism knife winrm command parallelism Feb 5, 2016
@nwesoccer
Copy link
Author

Was not able to test version 1.0.0.rc.0 or 1.0.0.rc.1 due to runtime errors, but 1.0.0.rc.2 has the same issues. So this was somewhere between 0.8.6 and 1.0.0.rc.2.

@mwrock
Copy link
Member

mwrock commented Feb 8, 2016

Yeah the parallelism seems like it was lost when em-winrm was deprecated which is indeed unfortunate. Would be cool to get this back. Perhaps with a new gem winrm-multi.

@spuder
Copy link
Contributor

spuder commented Feb 22, 2016

+1

@Valiev
Copy link

Valiev commented Mar 1, 2016

+1 as well

@chef09210
Copy link

chef09210 commented Apr 25, 2016

But it was depreciated because the functionality was put into knife-windows... you can't say it was depreciated because it was placed into knife-windows and then not in knife-windows because it was depreciated...

Also if this functionality was dropped for some reason the comments about supporting parallelism should be removed from the description

@chef09210
Copy link

Looks like from this commit #94 which I don't know why was approved

@jhenry82
Copy link

jhenry82 commented Jun 11, 2016

Any update on this issue? I started the charge to get my company's Windows servers under Chef management. But quickly hit a wall where a "knife winrm roles:windows_server chef-client" took 30+ minutes to run across like 10 servers. Which is insane, as the same thing across our 1000 Linux servers takes 5 minutes tops. Watching the console output, it's obviously running chef-client sequentially on each server and waiting for it to finish before moving on to the next.

This is still slightly better than logging into each box and clicking buttons in the GUI, but not much.

@spuder
Copy link
Contributor

spuder commented Jun 11, 2016

Ways to work around the current lack of parallelism in knife winrm. Use one of the following tools to trigger chef-client.

Using pure powershell to Invoke-command

for ($i = 15;$i -le 20; $i++){Invoke-Command -ComputerName "us-webserver$($i)" -ScriptBlock {chef-client}}

OR

You can have a little loop that runs 5 or so in parallel like this:

for ($i = 1;$i -le 5; $i++){Start-Job -ScriptBlock {Invoke-Command -ComputerName "us-webserver0$($args[0])" -ScriptBlock {chef-client}} -ArgumentList @($i)}
get-job | wait-job
get-job | receive-job
get-job | remove-job

I started using rundeck + chef push jobs for windows nodes. Unfortunately chef push jobs doesn't have the concept of parallelism either so I wrote a bash script that uses gnu parallel to call "chef push jobs" in batches. Rundeck is then just a gui to call the script.

The advantages of this method is you don't have to mess with winrm authentication.

#!/bin/bash
# Default variables
chef_search_string=${1:-'chef_environment:test AND role:web-server'}
number_of_nodes=${2:-'1'}

declare -a available_nodes=($(knife node status | grep 'available'| awk '{print $1}'))
declare -a chef_nodes=($(knife search node "${chef_search_string}" -i))
# mktemp creates a random folder in /tmp (you know, for security)
COMMANDS=$(mktemp)
for i in "${chef_nodes[@]}"
do
  :
  # Filter only nodes with status 'available', save good nodes to script file. 
  if echo ${available_nodes[@]} | grep -q -w "$i"; then
      echo "Adding node ${i} to list"
      echo "knife job start 'chef-client' -q 1 $i" >> $COMMANDS
  else
      echo "Node ${i} is not communicating with chef push jobs server"
  fi
done
cat $COMMANDS
echo "Starting push jobs, ${number_of_nodes} at a time...."
# each line in $commands file, is a command to run, gnu parallels executes those commands in batches
parallel --jobs ${number_of_nodes} --halt-on-error 1 < $COMMANDS
exit_code=$?
rm $COMMANDS
exit $exit_code

You then call the bash script with a chef search string, and then batch size. E.G.

foo.sh 'chef_environment:test AND role:web-server' 5

Its a shame that there isn't an easier way to do orchestration with chef on windows right now. Rumor has it that chef push jobs 2.0 should be out later this year which does support parallel orchestration.

@aqueeb
Copy link

aqueeb commented Aug 22, 2016

My colleagues and I stumbled on this issue today and came upon this thread. My colleague downgraded his knife-windows gem and is saying parallel threads work, I'll see it in action tomorrow and report back.

I was just wondering if there was any progress here? Are we going to get back parallel threads in knife-windows?

@mwrock
Copy link
Member

mwrock commented Aug 23, 2016

There are plans to do some fairly serious overhaul to winrm behavior here including better support for powershell, the ability to run commands via scheduled task in addition to the parallelism.

Much of this will start after the release of WinRb/WinRM#191 sothat we don't have to overhaul the winrm integration twice.

@aqueeb
Copy link

aqueeb commented Aug 24, 2016

When is WinRb/WinRM slated to release?

For everyone else coming to this page through Google, my colleague just downgraded his gem to 0.8.6 and got parallelism back.

@brendonmartino
Copy link

+1

@aqueeb
Copy link

aqueeb commented Dec 1, 2016

Just wondering if we will get parallelism back in knife winrm anytime soon?

@aqueeb
Copy link

aqueeb commented Jan 24, 2017

Using the latest version of chef-client (12.17.44) and still knife winrm is running serially. Maybe close this issue off if there is no plan on making knife winrm run in parallel over multiple hosts?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants