Navigation Menu

Skip to content

Commit

Permalink
serverspec init
Browse files Browse the repository at this point in the history
command:

$ serverspec-init
  • Loading branch information
mknkisk committed May 8, 2016
1 parent f229cf3 commit 6da107b
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .rspec
@@ -0,0 +1,2 @@
--color
--format documentation
27 changes: 27 additions & 0 deletions Rakefile
@@ -0,0 +1,27 @@
require 'rake'
require 'rspec/core/rake_task'

task :spec => 'spec:all'
task :default => :spec

namespace :spec do
targets = []
Dir.glob('./spec/*').each do |dir|
next unless File.directory?(dir)
target = File.basename(dir)
target = "_#{target}" if target == "default"
targets << target
end

task :all => targets
task :default => :all

targets.each do |target|
original_target = target == "_default" ? target[1..-1] : target
desc "Run serverspec tests to #{original_target}"
RSpec::Core::RakeTask.new(target.to_sym) do |t|
ENV['TARGET_HOST'] = original_target
t.pattern = "spec/#{original_target}/*_spec.rb"
end
end
end
1 change: 1 addition & 0 deletions Vagrantfile
Expand Up @@ -13,6 +13,7 @@ Vagrant.configure(2) do |config|
# Every Vagrant development environment requires a box. You can search for
# boxes at https://atlas.hashicorp.com/search.
config.vm.box = "ubuntu/trusty64"
config.vm.hostname = "localhost.ubuntu"

# Disable automatic box update checking. If you disable this, then
# boxes will only be checked for updates when the user runs
Expand Down
28 changes: 28 additions & 0 deletions spec/localhost.ubuntu/sample_spec.rb
@@ -0,0 +1,28 @@
require 'spec_helper'

describe package('httpd'), :if => os[:family] == 'redhat' do
it { should be_installed }
end

describe package('apache2'), :if => os[:family] == 'ubuntu' do
it { should be_installed }
end

describe service('httpd'), :if => os[:family] == 'redhat' do
it { should be_enabled }
it { should be_running }
end

describe service('apache2'), :if => os[:family] == 'ubuntu' do
it { should be_enabled }
it { should be_running }
end

describe service('org.apache.httpd'), :if => os[:family] == 'darwin' do
it { should be_enabled }
it { should be_running }
end

describe port(80) do
it { should be_listening }
end
41 changes: 41 additions & 0 deletions spec/spec_helper.rb
@@ -0,0 +1,41 @@
require 'serverspec'
require 'net/ssh'
require 'tempfile'

set :backend, :ssh

if ENV['ASK_SUDO_PASSWORD']
begin
require 'highline/import'
rescue LoadError
fail "highline is not available. Try installing it."
end
set :sudo_password, ask("Enter sudo password: ") { |q| q.echo = false }
else
set :sudo_password, ENV['SUDO_PASSWORD']
end

host = ENV['TARGET_HOST']

`vagrant up #{host}`

config = Tempfile.new('', Dir.tmpdir)
config.write(`vagrant ssh-config #{host}`)
config.close

options = Net::SSH::Config.for(host, [config.path])

options[:user] ||= Etc.getlogin

set :host, options[:host_name] || host
set :ssh_options, options

# Disable sudo
# set :disable_sudo, true


# Set environment variables
# set :env, :LANG => 'C', :LC_MESSAGES => 'C'

# Set PATH
# set :path, '/sbin:/usr/local/sbin:$PATH'

0 comments on commit 6da107b

Please sign in to comment.