Introduisez serverspec dans l'environnement Linux.
Créez un environnement Linux. https://qiita.com/mkuser9/items/079cc4244821c8e220c2
Les spécifications du serveur nécessitent ruby.
console
$ sudo yum -y install git
$ sudo yum install -y gcc gcc-c++ libyaml-devel libffi-devel libxml2 libxslt libxml2-devel libslt-devel
$ sudo yum install git-core
$ git clone https://github.com/rbenv/rbenv.git ~/.rbenv
$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
$ echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
$ exec $SHELL -l
$ source ~/.bash_profile
$ git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
$ sudo yum install -y bzip2 gdbm-devel openssl-devel libffi-devel libyaml-devel ncurses-devel readline-devel zlib-devel
$ RUBY_CONFIGURE_OPTS=--disable-install-doc ~/.rbenv/bin/rbenv install 2.6.3
$ rbenv global 2.6.3 && rbenv rehash
Créez un Gemfile et ajoutez "gem".
console
$ sudo vi Gemfile
Gemfile
source "https://rubygems.org"
gem 'serverspec'
gem 'rake'
console
$ bundle install
Installez serverspec avec la commande suivante.
console
$ gem install serverspec
console
$ serverspec-init
Select OS type:
1) UN*X
2) Windows
Select number: 1
Select a backend type:
1) SSH
2) Exec (local)
Select number: 2
Vagrant instance y/n: n
Input target host name: www.example.jp
+ spec/
+ spec/www.example.jp/
+ spec/www.example.jp/sample_spec.rb
+ spec/spec_helper.rb
+ Rakefile
+ .rspec
Le fichier de test est généré dans spec / localhost / sample_spec.rb
, donc modifiez le fichier de test en fonction du contenu du test.
console
vi spec/localhost/sample_spec.rb
Écrivez le test dans sample_spec.rb
.
sample_spec.rb(sample)
require 'spec_helper'
describe "Tester git" do
context "Cadre environnemental" do
describe package('git'), :if => os[:family] == 'redhat' do
it "installée" do
expect be_installed
end
end
end
end
describe "git-Tester le cœur" do
context "Cadre environnemental" do
describe package('git-core'), :if => os[:family] == 'redhat' do
it "installée" do
expect be_installed
end
end
end
end
describe "Test pour httpd" do
context "Cadre environnemental" do
describe package('httpd'), :if => os[:family] == 'redhat' do
it "installée" do
expect be_installed
end
it "Activée" do
expect be_enabled
end
it "Fonctionnement" do
expect be_running
end
end
end
end
describe "Tester le port" do
context "Cadre environnemental" do
describe port(80) do
it "Être écouté" do
expect be_listening
end
end
end
end
État initial de sample_spec.rb
.
sample_spec.rb(default)
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
Exécutez le test avec la commande suivante.
console
$ rake spec
Recommended Posts