Class: Bolt::Transport::SSH

Inherits:
Simple show all
Defined in:
lib/bolt/transport/ssh.rb,
lib/bolt/transport/ssh/connection.rb,
lib/bolt/transport/ssh/exec_connection.rb

Defined Under Namespace

Classes: Connection, ExecConnection

Instance Attribute Summary

Attributes inherited from Base

#logger

Instance Method Summary collapse

Methods inherited from Simple

#connected?, #download, #run_command, #run_script, #run_task, #upload

Methods inherited from Base

#assert_batch_size_one, #batch_command, #batch_connected?, #batch_download, #batch_script, #batch_task, #batch_task_with, #batch_upload, #batches, #connected?, #default_input_method, #download, #provided_features, #run_command, #run_script, #run_task, #select_implementation, #select_interpreter, #unwrap_sensitive_args, #upload, #with_events

Constructor Details

#initializeSSH

Returns a new instance of SSH.



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/bolt/transport/ssh.rb', line 10

def initialize
  super

  require 'net/ssh'
  require 'net/scp'
  begin
    require 'net/ssh/krb'
  rescue LoadError
    logger.debug("Authentication method 'gssapi-with-mic' (Kerberos) is not available.")
  end
  @transport_logger = Bolt::Logger.logger(Net::SSH)
  @transport_logger.level = :warn
end

Instance Method Details

#with_connection(target) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/bolt/transport/ssh.rb', line 24

def with_connection(target)
  if target.transport_config['ssh-command'] && !target.transport_config['native-ssh']
    Bolt::Logger.warn_once("native_ssh_disabled", "native-ssh must be true to use ssh-command")
  end

  conn = if target.transport_config['native-ssh']
           ExecConnection.new(target)
         else
           Connection.new(target, @transport_logger)
         end
  conn.connect
  yield conn
ensure
  begin
    conn&.disconnect
  rescue StandardError => e
    logger.info("Failed to close connection to #{target.safe_name} : #{e.message}")
  end
end