Sha256: 820c6853bab42256bb9f88dfd356d54a8b3c3f5e413f83da45c346e24c7c187d

Contents?: true

Size: 1.2 KB

Versions: 9

Compression:

Stored size: 1.2 KB

Contents

require 'yaml'
class Subspace::Commands::Ssh < Subspace::Commands::Base
  PASS_THROUGH_PARAMS = ["i"]

  def initialize(args, options)
    @host = args.first
    @user = options.user
    @options = options
    run
  end

  def run
    if !File.exists? "config/provision/host_vars/#{@host}"
      say "No host '#{@host}' found. "
      all_hosts = Dir["config/provision/host_vars/*"].collect {|f| File.basename(f) }
      say (["Available hosts:"] + all_hosts).join("\n\t")
      return
    end
    host_vars = YAML.load_file("config/provision/host_vars/#{@host}")
    user = @user || host_vars["ansible_ssh_user"] || host_vars["ansible_user"]
    host = host_vars["ansible_ssh_host"] || host_vars["ansible_host"]
    port = host_vars["ansible_ssh_port"] || host_vars["ansible_port"] || 22
    ssh_options = []
    PASS_THROUGH_PARAMS.each do |param_name|
      x = param_name.split('-')[1..-1].map(&:upcase).join('_')
      hash_key = (param_name.gsub('-', '_') + (x == '' ? '' : "_#{x}")).to_sym
      value = @options.__hash__[hash_key]
      if value
        ssh_options += ["-#{param_name}", value]
      end
    end
    cmd = "ssh #{user}@#{host} -p #{port} #{ssh_options.join(" ")}"
    say cmd
    exec cmd
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
subspace-2.1.2 lib/subspace/commands/ssh.rb
subspace-2.1.1 lib/subspace/commands/ssh.rb
subspace-2.1.0 lib/subspace/commands/ssh.rb
subspace-2.0.4 lib/subspace/commands/ssh.rb
subspace-2.0.3 lib/subspace/commands/ssh.rb
subspace-2.0.2 lib/subspace/commands/ssh.rb
subspace-2.0.1 lib/subspace/commands/ssh.rb
subspace-2.0.0 lib/subspace/commands/ssh.rb
subspace-1.0.8 lib/subspace/commands/ssh.rb