Class: Subspace::Commands::Ssh
- Defined in:
- lib/subspace/commands/ssh.rb
Constant Summary collapse
- PASS_THROUGH_PARAMS =
["i"]
Instance Method Summary collapse
-
#initialize(args, options) ⇒ Ssh
constructor
A new instance of Ssh.
- #run ⇒ Object
Methods inherited from Base
#confirm_overwrite, #copy, #dest_dir, #gem_path, #inventory, #pass_through_params, #playbook_dir, #project_name, #project_path, #require_configuration, #set_subspace_version, #template, #template!, #template_dir
Methods included from Ansible
#ansible_command, #ansible_playbook
Constructor Details
#initialize(args, options) ⇒ Ssh
Returns a new instance of Ssh.
6 7 8 9 10 11 |
# File 'lib/subspace/commands/ssh.rb', line 6 def initialize(args, ) @host = args.first @user = .user @options = run end |
Instance Method Details
#run ⇒ Object
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 |