Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
command: $ serverspec-init
- Loading branch information
Showing
5 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
--color | ||
--format documentation |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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' |