Last active
August 29, 2015 14:06
-
-
Save rrreeeyyy/83c6657d8bfa7186136a to your computer and use it in GitHub Desktop.
serverspec-sshkey-passphrase
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'serverspec' | |
require 'pathname' | |
require 'net/ssh' | |
require 'highline/import' | |
include Serverspec::Helper::Ssh | |
include Serverspec::Helper::DetectOS | |
RSpec.configure do |c| | |
if ENV['ASK_SUDO_PASSWORD'] | |
c.sudo_password = ask("Enter sudo password: ") { |q| q.echo = false } | |
else | |
c.sudo_password = ENV['SUDO_PASSWORD'] | |
end | |
c.host = host | |
options = Net::SSH::Config.for(c.host) | |
if ENV['ASK_KEY_PASSPHRASE'] | |
options[:passphrase] = ask("\nEnter passphrase for key: ") { |q| q.echo = false } | |
else | |
options[:passphrase] = ENV['KEY_PASSPHRASE'] | |
end | |
user = options[:user] || Etc.getlogin | |
c.ssh = Net::SSH.start(c.host, user, options) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ssh-agent 使うのがどうしても嫌な人向け