feat: try serverspec
DESCRIPTION Used local runner to perform the following tasks on my Arch Linux dev machine 1. Check if apache is installed on arch 2. Check if httpd service is enabled and running 3. Check if port 80 is listening COMMENTS Limited capabilities but seems to have support for basic testing on mulitple environments: local, SSH and Docker API using multiple configuration management tools like Puppet and Ansible. REFERENCES [0]: https://serverspec.org/tutorial.html [1]: https://serverspec.org/resource_types.html
This commit is contained in:
parent
d48a9f8e01
commit
a24e814a1a
5 changed files with 71 additions and 0 deletions
2
sandbox/serverspec/getting-started/.rspec
Normal file
2
sandbox/serverspec/getting-started/.rspec
Normal file
|
@ -0,0 +1,2 @@
|
|||
--color
|
||||
--format documentation
|
1
sandbox/serverspec/getting-started/Gemfile
Normal file
1
sandbox/serverspec/getting-started/Gemfile
Normal file
|
@ -0,0 +1 @@
|
|||
gem 'serverspec'
|
27
sandbox/serverspec/getting-started/Rakefile
Normal file
27
sandbox/serverspec/getting-started/Rakefile
Normal file
|
@ -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
|
|
@ -0,0 +1,37 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe package('apache'), if: os[:family] == 'arch' do
|
||||
it { should be_installed }
|
||||
end
|
||||
|
||||
describe service('httpd'), if: os[:family] == 'arch' do
|
||||
it { should be_enabled }
|
||||
it { should be_running }
|
||||
end
|
||||
|
||||
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
|
4
sandbox/serverspec/getting-started/spec/spec_helper.rb
Normal file
4
sandbox/serverspec/getting-started/spec/spec_helper.rb
Normal file
|
@ -0,0 +1,4 @@
|
|||
require 'serverspec'
|
||||
|
||||
set :backend, :exec
|
||||
|
Loading…
Add table
Reference in a new issue