Sha256: 6f28dfb3861d3106ba74cc00301acdca7a8387c421c2708669d602727e37457c

Contents?: true

Size: 943 Bytes

Versions: 3

Compression:

Stored size: 943 Bytes

Contents

require 'parallel'

module Koma
  module Backend
    class Ssh < Base
      def gather
        if host.include?(',')
          list = host.split(',').uniq
          results = Parallel.map(list) do |h|
            gather_via_ssh(h, options)
          end
          arr = [list, results].transpose
          result = Hash[*arr.flatten]
        else
          result = gather_via_ssh(host, options)
        end
        result
      end

      def gather_via_ssh(host, options)
        user, host = host.split('@') if host.include?('@')
        set :backend, :ssh
        set :host, host
        set :request_pty, true
        ssh_options = Net::SSH::Config.for(host)
        ssh_options[:user] = user if user
        ssh_options[:keys] = [options[:identity_file]] if options[:identity_file]
        ssh_options[:port] = options[:port] if options[:port]
        set :ssh_options, ssh_options
        out(options[:key])
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
koma-0.8.0 lib/koma/backend/ssh.rb
koma-0.7.3 lib/koma/backend/ssh.rb
koma-0.7.2 lib/koma/backend/ssh.rb