Method: KnifeCloudformation::Utils::Ssher#remote_file_contents

Defined in:
lib/knife-cloudformation/utils/ssher.rb

#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/knife-cloudformation/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