Hi,

Sylvain Viart a écrit :
>> It would seem reasonable for session.exec to collect the status of 
>> each of the threads and return an array of them. I don't know if it 
>> does so. Perhaps you can use something like this:
>>
>>     errs = []
>>     ...
>>       :on_error => lambda { |server| errs << server }
>>     ...
>>     session.exec "hostname"
>>     unless errs.empty?
>>       puts "The command failed on #{errs.size} hosts"
>>     end   
> Hum, nice, I'm gonna try. :-)
> Would it catch the Errno::EHOSTUNREACH?
It didn't catch the exception

a workaround, using a closure and Net::SSH::Multi::DynamicServer 
<http://net-ssh.rubyforge.org/multi/v1/api/classes/Net/SSH/Multi/DynamicServer.html> 
behavior, instead of specifying the server. It's evaluated by attempting he ssh connection first. Which  mean the server, is connected twice, 
during the test and later in the session. Note that I discard the 
'options' to test the connection.

errs = []
def test_server(errs, server)
    lambda do |options|
        begin
            server =~ /(.+)@(.+)/
            server_name, user = $2, $1
            puts server_name
            s = Net::SSH.start(server_name, user)
            s.close
            s = server
        rescue Errno::EHOSTUNREACH, SocketError
            puts "echec connexion #{server} : #{$!}"
            errs << server
            s = nil
        end

        return s
    end
end

Net::SSH::Multi.start(:on_error => :warn) do |session|
  # define the servers we want to use
  session.use &test_server(errs, 'root@srv-04')
  session.use &test_server(errs, 'root@srv-07')
  session.use &test_server(errs, 'root@srv-08')
  session.use &test_server(errs, 'root / fail-08.local')

  # execute commands on all servers
  session.exec( "hostname" )


  # run the aggregated event loop
  session.loop
end

unless errs.empty?
  puts "The command failed on #{errs.size} hosts"
end

#srv-04
#srv-07
#echec connexion root@srv-07 : No route to host - connect(2)
#srv-08
#fail-08.local
#echec connexion root / fail-08.local : getaddrinfo: Name or service not known
#[srv-04] srv-04
#[srv-08] srv-08
#The command failed on 2 hosts

Works, but I still don't know why the exception are not handled in the 
lib Net::SSH::Multi which may be specific to this lib.
I still appreciate some more hint.

Regards,
Sylvain.