Module: Pawnee::SshConnection

Included in:
Base
Defined in:
lib/pawnee/pawnee/ssh_connection.rb

Instance Method Summary collapse

Instance Method Details

#reconnect!Object

Reconnects to the remote server (using net/ssh). This is useful since often things in linux don’t take effect until the user creates a new login shell (adding a user to a group for example)



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/pawnee/pawnee/ssh_connection.rb', line 7

def reconnect!
  host = self.destination_connection.host
  options = self.destination_connection.options
  user = options[:user]
  
  # Close the existing connection
  self.destination_connection.close
  
  # Reconnect
  new_connection = Net::SSH.start(host, user, options)
  
  # Copy the instance variables to the old conection so we can keep using
  # the same session without reassigning references
  self.destination_connection.instance_variables.each do |variable_name|
    value = new_connection.instance_variable_get(variable_name)
    self.destination_connection.instance_variable_set(variable_name, value)
  end
end