diff options
-rw-r--r-- | lib/shell_utils.rb | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/lib/shell_utils.rb b/lib/shell_utils.rb index 75ee3ca..b426e44 100644 --- a/lib/shell_utils.rb +++ b/lib/shell_utils.rb @@ -73,15 +73,27 @@ module ShellUtils def read_json_file(filename, from_remote_host: nil) if from_remote_host + identity_file = Tempfile.new( + 'private-identity-file', + Rails.root.join('tmp') + ) + identity_file.write(from_remote_host.private_key) + identity_file.close + command = [ 'ssh', - from_remote_host, + from_remote_host.user_at_address, + # Use a automatically trust on first use model + '-o', 'StrictHostKeyChecking=no', + '-i', identity_file.path, 'cat', filename ] stdout_str, status = Open3.capture2(*command) + identity_file.unlink if identity_file + unless status.exitstatus == 0 logger.error(self.class) { "failed, exit status #{exit_status}" } |