Reputation: 8497
Referencing the net-ssh API, what's the "best" way to pass connection parameters which come from a yaml?
error:
thufir@dur:~/ruby$
thufir@dur:~/ruby$ ruby ssh.rb
{:host=>"localhost", :user=>"me", :port=>123, :password=>"mypassword"}
/home/thufir/.rvm/gems/ruby-2.0.0-p247/gems/net-ssh-2.6.8/lib/net/ssh.rb:165:in `start': wrong number of arguments (1 for 2..3) (ArgumentError)
from ssh.rb:14:in `<main>'
thufir@dur:~/ruby$
code:
#!/usr/bin/env ruby
require 'rubygems'
require 'net/ssh'
require 'yaml'
require 'pry'
conn = YAML.load_file('conn.yml')
params = {:host => conn['host'], :user => conn['user'],
:port => conn['port'],:password => conn['password']}
puts params
Net::SSH.start(params) do |ssh|
puts 'hi'
end
yaml:
user: me
password: mypassword
port: 123
host: localhost
is it possible to just pass one monolithic object? Or, do you have to break it up into host, user, et. al.?
Upvotes: 0
Views: 471
Reputation: 223133
The host
and user
arguments must be specified as positional arguments, not as part of the options
hash. Thus:
Net::SSH.start(conn['host'], conn['user'], port: conn['port'], password: conn['password']) do |ssh|
# ...
end
Or you can just pass through all the YAML key-value pairs directly:
Net::SSH.start(conn.delete('host'), conn.delete('user'), conn) do |ssh|
# ...
end
Upvotes: 4