Skip to content

Instantly share code, notes, and snippets.

@pburkholder
Last active December 2, 2015 19:02
Show Gist options
  • Save pburkholder/05455d33d4a9f83a54b6 to your computer and use it in GitHub Desktop.
Save pburkholder/05455d33d4a9f83a54b6 to your computer and use it in GitHub Desktop.

Running killssh with patched version of net-ssh

From project dir:

git clone https://github.com/causton81/net-ssh.git
cd net-ssh
git checkout causton81/channel_close_after_output
cd ..
git clone https://github.com/chef/chef.git
cd chef
git checkout 12.5.1

git patch <<END
diff --git a/chef.gemspec b/chef.gemspec
index b1abe76..828ee14 100644
--- a/chef.gemspec
+++ b/chef.gemspec
@@ -24,7 +24,7 @@ Gem::Specification.new do |s|
   s.add_dependency "ohai", ">= 8.6.0.alpha.1", "< 9"

   s.add_dependency "ffi-yajl", "~> 2.2"
-  s.add_dependency "net-ssh", "~> 2.6"
+  s.add_dependency "net-ssh", "~> 3.0"
   s.add_dependency "net-ssh-multi", "~> 1.1"
   s.add_dependency "highline", "~> 1.6", ">= 1.6.9"
   s.add_dependency "erubis", "~> 2.7"
END

cd ..
git clone https://github.com/chef/chef-provisioning.git
cd chef-provisioning
git checkout v1.5.0
# edit Gemfile
# -#gem 'net-ssh', :path => '../net-ssh'
# -#gem 'chef', :path => '../chef'
# +gem 'net-ssh', :path => '../net-ssh'
# +gem 'chef', :path => '../chef'

# edit chef-provisioning.gemspec
# Change to net-ssh ~> 3.0

Then build in chef-provisioning with bundle install --path vendor/bundle

Checkout a provisioning cookbook into chef-provisioning

cd <cookbook>
# add latency
sudo tc qdisc add dev eth0 root netem delay 120ms 20ms

Test the original

chef-client -z recipes/default.rb
# should fail

Test patch

bundle exec chef-client -z recipes/default.rb
# should work
#!/usr/bin/env ruby
require 'rubygems'
require 'net/ssh'
remote_ip = ARGV[0]
remote_user = ARGV[1]
remote_port = (ARGV[2].nil? ? '8889' : ARGV[2]).to_i
if remote_ip.nil?
print "Usage: ./tunnel.rb remote_ip remote_user [remote_port]\n"
exit 1
end
Net::SSH.start(remote_ip, remote_user) do |ssh|
print "Opening to #{remote_user}@#{remote_ip} on port #{remote_port}\n"
ssh.forward.remote(remote_port, "localhost", remote_port)
ssh.loop { true }
end
@causton81
Copy link

Nice!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment