-
rubyからsshで複数サーバーに対して操作がしたかったのでnet-ssh-multi gem(1.2.0)を使ってみた
-
capistranoはコマンドラインツールとしては引数がわかりにくいけどnet-ssh-multi + trollopあたりだと気楽にコマンドラインツール作れるかな?
-
サンプルスクリプト
-
SOCKS5プロキシを利用する環境なので指定
-
concurrent_connectionsで最大コネクション数を指定
require 'net/ssh/multi'
require 'net/ssh/proxy/socks5'
socks5 = Net::SSH::Proxy::SOCKS5.new('host', 1080, :user => 'user', :password => 'password')
Net::SSH::Multi.start(concurrent_connections => 1) do |session|
session.use "[ec2のPublicDNS1]",
"[ec2のPublicDNS2]",
:user => 'ec2-user',
:proxy => socks5,
:keys => ["/private/key/path"]
session.exec "echo hoge"
session.loop
end
- 実行結果
$ bundle exec ruby test.rb
[ec2のPublicDNS1] hoge
[ec2のPublicDNS2] hoge