5. 利用方法
2018/05/26 かごもく #8 でばっぐ 5
実行
$ rake spec:webhost.cc.kagoshima-u.ac.jp
結果
$ rake spec:webhost.cc.kagoshima-u.ac.jp ASK_SUDO_PASSWORD=1
Enter sudo password:
Package "httpd"
should be installed
Service "httpd"
should be enabled
should be running
Port "80"
should be listening
Finished in 1.48 seconds (files took 6.75 seconds to load)
4 examples, 0 failures
$
7. specファイルについて(1)
リソースタイプ(resource type)
マッチャー(matcher)
2018/05/26 かごもく #8 でばっぐ 7
sample_spec.rb (抜粋)
require 'spec_helper'
describe package('httpd') do
it { should be_installed }
end
describe service('httpd') do
it { should be_enabled }
it { should be_running }
end
describe port(80) do
it { should be_listening }
end
パッケージ httpd は
インストールされているか?
サービス httpd は
(起動時)有効になっ
ているか?
(現在)起動している
か?
8. specファイルについて(2)
リソースタイプごとに一部マッチャーは決まっている
◦ もちろん rspec 由来のマッチャーも利用可能
どんなリソースタイプがあるのか?
https://serverspec.org/resource_types.html
2018/05/26 かごもく #8 でばっぐ 8
describe user('simozono') do
it { is_expected.to exist }
it { is_expected.to belong_to_group 'wheel' }
it { is_expected.to have_uid 1101 }
it { is_expected.to have_home_directory "/home/simozono" }
it { is_expected.to have_login_shell '/bin/bash' }
end
describe interface('ens160') do
it { is_expected.to exist }
it { is_expected.to be_up }
it { is_expected.to have_ipv4_address "192.168.1.241/24" }
end
describe file '/etc/ntp.conf' do
time_cc_regex = /^server[ t]+timeserver.kagoshima-u.ac.jp/
sinet_ntp_regex = /^server[ t]+ntp[01]1.sinet.ad.jp/
its(:content) { is_expected.to match time_cc_regex }
its(:content) { is_expected.to match sinet_ntp_regex }
end