module Sfn::Utils::Ssher

Helper methods for SSH interactions

Public Instance Methods

remote_file_contents(address, user, path, ssh_opts = {}) click to toggle source

Retrieve file from remote node

@param address [String] @param user [String] @param path [String] remote file path @param ssh_opts [Hash] @return [String, NilClass]

# 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