Created
March 27, 2014 16:08
-
-
Save gavinrogers/9811138 to your computer and use it in GitHub Desktop.
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 'yaml' | |
include Serverspec::Helper::Ssh | |
include Serverspec::Helper::DetectOS | |
include Serverspec::Helper::Properties | |
test = 'jenkins-master' | |
if match = /(?=^.{4,255}$)(^((?!-)[a-zA-Z0-9-]{1,63}(?<!-)\.)+[a-zA-Z]{2,63}$)/.match(test) | |
p 'it matches' | |
end | |
# p 'it doesnt match' | |
#end | |
#RSpec.configure do |c| | |
# c.host = ENV['TARGET_HOST'] | |
# set_property properties[c.host] | |
# options = Net::SSH::Config.for(c.host) | |
# user = options[:user] || Etc.getlogin | |
# c.ssh = Net::SSH.start(c.host, user, options) | |
# c.os = backend.check_os | |
#end | |
RSpec.configure do |c| | |
if ENV['ASK_SUDO_PASSWORD'] | |
require 'highline/import' | |
c.sudo_password = ask("Enter sudo password: ") { |q| q.echo = false } | |
else | |
c.sudo_password = ENV['SUDO_PASSWORD'] | |
end | |
c.before :all do | |
block = self.class.metadata[:example_group_block] | |
if RUBY_VERSION.start_with?('1.8') | |
file = block.to_s.match(/.*@(.*):[0-9]+>/)[1] | |
else | |
file = block.source_location.first | |
end | |
#host = File.basename(Pathname.new(file).dirname) | |
sleep 5 | |
c.host = ENV['TARGET_HOST'] | |
#set_property properties[c.host] | |
#if c.host != host | |
c.ssh.close if c.ssh | |
#c.host = host | |
options = Net::SSH::Config.for(c.host) | |
user = options[:user] || Etc.getlogin | |
puts "the host is #{c.host}" | |
unless c.host !=~ /(?=^.{4,255}$)(^((?!-)[a-zA-Z0-9-]{1,63}(?<!-)\.)+[a-zA-Z]{2,63}$)/ | |
#vagrant_up = `vagrant up jenkins-master` | |
puts "it matches!!!!" | |
config = `vagrant ssh-config #{c.host}` | |
if config != '' | |
config.each_line do |line| | |
if match = /HostName (.*)/.match(line) | |
c.host = match[1] | |
elsif match = /User (.*)/.match(line) | |
user = match[1] | |
elsif match = /IdeniftityFile (.*)/.match(line) | |
options[:keys] = [match[1].gsub(/"/,'')] | |
elsif match = /Port (.*)/.match(line) | |
options[:port] = match[1] | |
end | |
end | |
end | |
end | |
puts c.host | |
puts options | |
user = 'gavinrogers' | |
puts user | |
puts c.user | |
c.ssh = Net::SSH.start(c.host, c.user, options) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment