Sha256: c4c227187b377877613f1a9ec4ca7d80da861704e5bd5194fbca8a630dca0451

Contents?: true

Size: 886 Bytes

Versions: 1

Compression:

Stored size: 886 Bytes

Contents

require 'net/ssh'

module Legion
  module Extensions
    module Ssh
      module Helpers
        module Connection
          def session(server:, user: 'root', **opts)
            hash = {}
            if opts.key? :password
              hash[:password] = opts[:password]
            elsif opts.key? :key_data
              hash[:key_data] = opts[:key_data]
            elsif opts.key? :keys
              hash[:keys] = opts[:keys]
            end
            hash[:non_interactive] = opts.key?(:non_interactive) ? opts[:non_interactive] : true
            hash[:passphrase] = opts[:passphrase] if opts.key? :passphrase
            hash[:timeout] = opts.key(:timeout) ? opts[:timeout] : 5

            Net::SSH.start(server, user, **hash)
          end

          def detect_os(session)
            session.exec!('lsb_release -a')
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
lex-ssh-0.1.1 lib/legion/extensions/ssh/helpers/connection.rb