Module: Sfn::Utils::Ssher

Included in:
Command::Inspect
Defined in:
lib/sfn/utils/ssher.rb

Overview

Helper methods for SSH interactions

Instance Method Summary collapse

Instance Method Details

#remote_file_contents(address, user, path, ssh_opts = {}) ⇒ String, NilClass

Retrieve file from remote node

Parameters:

  • address (String)
  • user (String)
  • path (String)

    remote file path

  • ssh_opts (Hash) (defaults to: {})

Returns:

  • (String, NilClass)


16
17
18
19
20
21
22
23
24
25
# File 'lib/sfn/utils/ssher.rb', line 16

def remote_file_contents(address, user, path, ssh_opts = {})
  if path.to_s.strip.empty?
    raise ArgumentError.new "No file path provided!"
  end
  require "net/ssh"
  content = ""
  ssh_session = Net::SSH.start(address, user, ssh_opts)
  content = ssh_session.exec!("sudo cat #{path}")
  content.empty? ? nil : content
end