Class: Spaux::CLI::SSHSubcommand
- Inherits:
-
Object
- Object
- Spaux::CLI::SSHSubcommand
- Defined in:
- lib/spaux/cli/ssh_subcommand.rb
Instance Method Summary collapse
-
#initialize(*args) ⇒ SSHSubcommand
constructor
A new instance of SSHSubcommand.
- #run(nodename, options = {}) ⇒ Object
Constructor Details
#initialize(*args) ⇒ SSHSubcommand
Returns a new instance of SSHSubcommand.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/spaux/cli/ssh_subcommand.rb', line 9 def initialize(*args) chef_config = args.shift || {} spaux_config = args.shift || {} default_chef_config = Spaux::default_chef_config(:client) @config = {} @config.merge! default_chef_config.merge(chef_config) default_spaux_config = Spaux::default_spaux_config @spaux_config = default_spaux_config.merge(spaux_config) @config[:raw_key] = Spaux::Chef::Key.new(@spaux_config).raw_key redefine_chef_http_authenticator @config[:raw_key] end |
Instance Method Details
#run(nodename, options = {}) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/spaux/cli/ssh_subcommand.rb', line 24 def run(nodename, ={}) begin node = ::Chef::Node.load(nodename) rescue Net::HTTPServerException => e not_found_msg = nodename + ' node could not be found in the server' STDERR.puts not_found_msg if e.response.code.eql?('404') end node_ipaddress = node[:ipaddress] node_rsa_public_key = node[:keys][:ssh][:host_rsa_public] # write a gem to do this instead of shelling out node_key = `ssh-keyscan -H #{node_ipaddress} 2>/dev/null` tmp_known_hosts_file = Tempfile.new('tmp_known_hosts_file') tmp_known_hosts_file.write(node_key) tmp_known_hosts_file.flush ssh_cmd = "ssh -o UserKnownHostsFile=" exec(ssh_cmd + "#{tmp_known_hosts_file.path} #{node_ipaddress}") end |