Ruby net-ssh-multi: passing a password as a parameter at runtime

I am trying to use net-ssh-multi to run a command on a group of servers. For this, taks ssh-key authentication is not an option; the password must be passed to each server defined in the session.use lines. Here the problem of "net / ssh" may take a password parameter, but "net / ssh / multi" cannot. I would like to do the following:

require 'net/ssh' require 'net/ssh/multi' #The necessary data is contained in a Ticket object my_ticket = Ticket.new Net::SSH::Multi.start (:password => 'xxxx') do |session| # define the servers we want to use my_ticket.servers.each do |serv_id| session.use "#{my_ticket.user_name}@#{serv_id}" end # execute commands on all servers session.exec "uptime" # run the aggregated event loop session.loop end 

However, this is me:

file.rb: 35: at `start ': wrong number of arguments (1 to 2) (ArgumentError) from file.rb: 35

I know this is a bit of a n00b issue, but I would really appreciate help.

(http://rubydoc.info/gems/net-ssh-multi/1.1/Net/SSH/Multi)

+2
source share
1 answer

It turns out the answer is much simpler than I thought. Understanding the documentation, I noticed this in the document Class: Net :: SSH :: Multi :: Server:

Class: Net :: SSH :: Multi :: Server

Overview:

Encapsulates the connection information for one remote server, as well as the Net :: SSH session corresponding to this information. You rarely have to do one of the following: instead, you should use Net :: SSH :: Multi :: Session # usage.

Thus, class extension or calls to superclasses are not required. The above can be accomplished with:

 require 'net/ssh' require 'net/ssh/multi' #The necessary data is contained in a Ticket object my_ticket = Ticket.new Net::SSH::Multi.start do |session| # define the servers we want to use my_ticket.servers.each do |session_server| session.use session_server , :user => my_ticket.user_name , \ :password => my_ticket.user_pass end # execute commands on all servers session.exec my_ticket.command_to_do # run the aggregated event loop session.loop end 
+1
source

All Articles