Class: Subspace::Commands::Ssh

Inherits:
Base
  • Object
show all
Defined in:
lib/subspace/commands/ssh.rb

Constant Summary collapse

PASS_THROUGH_PARAMS =
["i"]

Instance Method Summary collapse

Methods inherited from Base

#confirm_overwrite, #copy, #dest_dir, #gem_path, #pass_through_params, #playbook_dir, #project_path, #require_configuration, #template, #template!, #template_dir

Methods included from Ansible

#ansible_command

Constructor Details

#initialize(args, options) ⇒ Ssh

Returns a new instance of Ssh.



5
6
7
8
9
10
# File 'lib/subspace/commands/ssh.rb', line 5

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

Instance Method Details

#runObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/subspace/commands/ssh.rb', line 12

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
  cmd = "ssh #{user}@#{host} -p #{port} #{pass_through_params.join(" ")}"
  say cmd
  exec cmd
end