From 994f8a906beb73b43b89aca3e28c6d803a665c84 Mon Sep 17 00:00:00 2001 From: Tristan Ancelet Date: Fri, 28 Jun 2024 20:13:45 -0500 Subject: [PATCH] Added default user & error handling --- lib/host.rb | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/host.rb b/lib/host.rb index 9ac0ef5..8d22e6f 100644 --- a/lib/host.rb +++ b/lib/host.rb @@ -5,7 +5,7 @@ module RubyQA :hostname => "", :ip => "", :port => 22, - :user => "", + :user => ENV["USER"], :password => "", :site => "", :cluster => false, @@ -28,7 +28,16 @@ module RubyQA end def init_client - @client = Net::SSH.start(@data[:ip], @data[:user]) + begin + if @data[:password] + @client = Net::SSH.start(@data[:ip], @data[:user], password: @data[:password]) + else + @client = Net::SSH.start(@data[:ip], @data[:user]) + end + + rescue SocketError + raise "Failed to make ssh client for #{@data[:hostname]}" + end end def exec (command)