Method: Subspace::Commands::Ssh#run

Defined in:
lib/subspace/commands/ssh.rb

#runObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/subspace/commands/ssh.rb', line 13

def run
  if !inventory.hosts[@host]
    say "No host '#{@host}' found. "
    all_hosts = inventory.hosts.keys
    say (["Available hosts:"] + all_hosts).join("\n\t")
    return
  end
  host_vars = inventory.hosts[@host].vars
  if host_vars.key?('ansible_ssh_user')
    say "Supposed to be ansible_user not ansible_ssh_user"
  end
  user = @user || host_vars["ansible_user"]
  host = host_vars["ansible_host"]
  port = host_vars["ansible_port"] || 22
  pem = host_vars["ansible_ssh_private_key_file"]
  pem_cmd = "-i config/subspace/#{pem}" if pem
  cmd = "ssh #{user}@#{host} -p #{port} #{pem_cmd} #{pass_through_params.join(" ")}"
  say "> #{cmd} \n"
  exec cmd
end