Module: ZTK::SSH::Bootstrap
- Included in:
- ZTK::SSH
- Defined in:
- lib/ztk/ssh/bootstrap.rb
Overview
SSH Bootstrap Functionality
Instance Method Summary (collapse)
-
- (Object) bootstrap(content, options = {})
SSH Bootstrap.
Instance Method Details
- (Object) bootstrap(content, options = {})
SSH Bootstrap
Renders the content string into a file on the remote host and proceeds to execute it via /bin/bash. Sudo is prefixed by default, but can be disabled.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/ztk/ssh/bootstrap.rb', line 26 def bootstrap(content, ={}) = { :silence => true, :use_sudo => true, :set_x => true, :set_e => false }.merge() bootstrap_tempfile = Tempfile.new("bootstrap") remote_tempfile = ::File.join("", "tmp", ::File.basename(bootstrap_tempfile.path.dup)) bootstrap_tempfile.close! local_tempfile = Tempfile.new("tempfile-local") local_tempfile.puts(content) local_tempfile.respond_to?(:flush) and local_tempfile.flush command = Array.new command << %(sudo) if ([:use_sudo] == true) command << %(/bin/bash) command << %(-x) if ([:set_x] == true) command << %(-e) if ([:set_e] == true) command << remote_tempfile command = command.join(' ') self.upload(local_tempfile.path, remote_tempfile) result = self.exec(command, ) local_tempfile.close! result end |