Module: Net::SSH::Multi

Defined in:
lib/cute/net-ssh.rb

Overview

The Net::SSH::Multi aims at executing commands in parallel over a set of machines using the SSH protocol. One of the advantage of this module over TakTuk is that it allows to create groups, for example:

Net::SSH::Multi.start do |session|

   session.group :coord do
        session.use("root@#{coordinator}")
   end

   session.group :nodes do
         nodelist.each{ |node| session.use("root@#{node}")}
   end

   # test connection
   session.with(:coord).exec! "hostname"
   session.with(:nodes).exec! "hostname"

   # Check nfs paths
   tmp = session.exec! "ls -a #{ENV['HOME']}"

   # generating ssh password less connection
   session.exec! "cat .ssh/id_rsa.pub >> .ssh/authorized_keys"
end

However, with large set of nodes SSH it is limited an inefficient, for those cases the best option will be TakTuk. For complete documentation please take a look at / Net::SSH::Multi. One of the disadvantages of / Net::SSH::Multi is that it does not allow to capture the output (stdout, stderr and status) of executed commands. Ruby-Cute ships a monkey patch that extends the aforementioned module by adding the method exec! which blocks until the command finishes and captures the output (stdout, stderr and status).

require 'cute/net-ssh'

results = {}
Net::SSH::Multi.start do |session|

   # define the servers we want to use
   session.use 'user1@host1'
   session.use 'user2@host2'

   session.exec "uptime"
   session.exec "df"
   # execute command, blocks and capture the output
   results = session.exec! "date"
   # execute commands on a subset of servers
   session.exec "hostname"
end
puts results #=> {"node3"=>{:stdout=>"Wed Mar 11 12:38:11 UTC 2015", :status=>0},
             #    "node1"=>{:stdout=>"Wed Mar 11 12:38:11 UTC 2015", :status=>0}, ...}

Defined Under Namespace

Modules: SessionActions

Class Method Summary collapse

Class Method Details

.loggerObject

Returns logger.

Returns:

  • logger



72
73
74
75
76
77
78
# File 'lib/cute/net-ssh.rb', line 72

def self.logger
  if @logger.nil?
    @logger = Logger.new(STDOUT)
    logger.level = Logger::INFO
  end
  @logger
end

.logger=(v) ⇒ Object

sets logger to be used by net-ssh-multi module



67
68
69
# File 'lib/cute/net-ssh.rb', line 67

def self.logger= v
  @logger = v
end