aboutsummaryrefslogtreecommitdiff
path: root/lib/shell_utils.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/shell_utils.rb')
-rw-r--r--lib/shell_utils.rb14
1 files changed, 13 insertions, 1 deletions
diff --git a/lib/shell_utils.rb b/lib/shell_utils.rb
index 0cd8947..75ee3ca 100644
--- a/lib/shell_utils.rb
+++ b/lib/shell_utils.rb
@@ -20,6 +20,7 @@
require 'open3'
require 'shellwords'
+require 'tempfile'
module ShellUtils
def run_command(*command, run_remotely_on_host: nil)
@@ -28,11 +29,19 @@ module ShellUtils
Shellwords.escape(arg)
end
+ identity_file = Tempfile.new(
+ 'private-identity-file',
+ Rails.root.join('tmp')
+ )
+ identity_file.write(run_remotely_on_host.private_key)
+ identity_file.close
+
command = [
'ssh',
# Use a automatically trust on first use model
'-o', 'StrictHostKeyChecking=no',
- run_remotely_on_host,
+ '-i', identity_file.path,
+ run_remotely_on_host.user_at_address,
*command
]
end
@@ -52,9 +61,12 @@ module ShellUtils
unless exit_status == 0
logger.error(self.class) { "failed, exit status #{exit_status}" }
+ identity_file.unlink if identity_file
raise "Running #{command.join(' ')} failed:\n\n#{output.join}\n"
end
+ identity_file.unlink if identity_file
+
output
end
end