specファイルの書き方基本
をテンプレートにして作成
[
トップ
] [
新規
|
一覧
|
検索
|
最終更新
|
ヘルプ
|
ログイン
]
開始行:
[[Serverspec]]
*バージョン [#n7f0047b]
serverspec (2.25.0)
*パッケージ [#z6072d53]
***単一 [#wfaa15eb]
describe package('httpd')
it { should be_installed }
end
***複数 [#i21ebb0f]
%w{epel-release rsync gcc vim-enhanced}.each do |pkg|
describe package(pkg) do
it { should be_installed }
end
end
***パッケージのバージョン確認 [#l481b5c3]
[パターン1]
describe command( 'rpm -q openssl') do
it (:stdout) { should match(/openssl-0.9.8e-39/) }
end
[パターン2]
describe package('openssl') do
it { shuld be_installed.by('rpm').with_version('0.9.8e...
end
*サービス [#vfdec1d0]
***chkconfigが有効になっているかとサービスが起動している...
describe service('httpd')
it { should be_enabled }
it { should be_running }
end
***chkconfigが無効だった場合のエラー内容 [#f787a9c9]
should be enabled (FAILED - 1)
Failures:
1) Service "httpd" should be enabled
On host `192.168.33.11'
Failure/Error: it { should be_enabled }
expected Service "httpd" to be enabled
sudo -p 'Password: ' /bin/sh -c chkconfig\ --list\...
***サービスが稼働していなかった場合のエラー内容 [#j862b6bd]
Service "httpd"
should be running (FAILED - 2)
Failures:
2) Service "httpd" should be running
On host `192.168.33.11'
Failure/Error: it { should be_running }
expected Service "httpd" to be running
sudo -p 'Password: ' /bin/sh -c service\ httpd\ st...
httpd ????????????????????????
*ポート [#g3246545]
***ポートが開いているかの書き方 [#tb547203]
describe port(22) do
it { should be_listening }
end
***ポートが開いていなかった場合のエラー内容 [#xa73c23d]
Port "80"
should be listening (FAILED - 2)
Failures:
2) Port "80" should be listening
On host `192.168.33.11'
Failure/Error: it { should be_listening }
expected Port "80" to be listening
sudo -p 'Password: ' /bin/sh -c netstat\ -tunl\ \|...
***コマンドを実行してその標準出力の結果をチェック [#h4eb6...
describe command('cat /etc/sysconfig/clock') do
its(:stdout) { should match /ZONE="Asia\/Tokyo"/ }
end
[注意]
バージョン2からは「it { should return_stdout 〜」という...
http://serverspec.org/changes-of-v2.html
*ファイル [#z004e442]
*** 単一ファイルの存在確認 [#h3dcf153]
describe file("/etc/hosts") do
it { should be_file }
end
*** 複数ファイルの存在確認 [#e0e60206]
[
'hosts,
'resolv.conf'
].each do | conf |
describe file( "/etc/#{conf}" ) do
it { should be_file }
end
end
終了行:
[[Serverspec]]
*バージョン [#n7f0047b]
serverspec (2.25.0)
*パッケージ [#z6072d53]
***単一 [#wfaa15eb]
describe package('httpd')
it { should be_installed }
end
***複数 [#i21ebb0f]
%w{epel-release rsync gcc vim-enhanced}.each do |pkg|
describe package(pkg) do
it { should be_installed }
end
end
***パッケージのバージョン確認 [#l481b5c3]
[パターン1]
describe command( 'rpm -q openssl') do
it (:stdout) { should match(/openssl-0.9.8e-39/) }
end
[パターン2]
describe package('openssl') do
it { shuld be_installed.by('rpm').with_version('0.9.8e...
end
*サービス [#vfdec1d0]
***chkconfigが有効になっているかとサービスが起動している...
describe service('httpd')
it { should be_enabled }
it { should be_running }
end
***chkconfigが無効だった場合のエラー内容 [#f787a9c9]
should be enabled (FAILED - 1)
Failures:
1) Service "httpd" should be enabled
On host `192.168.33.11'
Failure/Error: it { should be_enabled }
expected Service "httpd" to be enabled
sudo -p 'Password: ' /bin/sh -c chkconfig\ --list\...
***サービスが稼働していなかった場合のエラー内容 [#j862b6bd]
Service "httpd"
should be running (FAILED - 2)
Failures:
2) Service "httpd" should be running
On host `192.168.33.11'
Failure/Error: it { should be_running }
expected Service "httpd" to be running
sudo -p 'Password: ' /bin/sh -c service\ httpd\ st...
httpd ????????????????????????
*ポート [#g3246545]
***ポートが開いているかの書き方 [#tb547203]
describe port(22) do
it { should be_listening }
end
***ポートが開いていなかった場合のエラー内容 [#xa73c23d]
Port "80"
should be listening (FAILED - 2)
Failures:
2) Port "80" should be listening
On host `192.168.33.11'
Failure/Error: it { should be_listening }
expected Port "80" to be listening
sudo -p 'Password: ' /bin/sh -c netstat\ -tunl\ \|...
***コマンドを実行してその標準出力の結果をチェック [#h4eb6...
describe command('cat /etc/sysconfig/clock') do
its(:stdout) { should match /ZONE="Asia\/Tokyo"/ }
end
[注意]
バージョン2からは「it { should return_stdout 〜」という...
http://serverspec.org/changes-of-v2.html
*ファイル [#z004e442]
*** 単一ファイルの存在確認 [#h3dcf153]
describe file("/etc/hosts") do
it { should be_file }
end
*** 複数ファイルの存在確認 [#e0e60206]
[
'hosts,
'resolv.conf'
].each do | conf |
describe file( "/etc/#{conf}" ) do
it { should be_file }
end
end
ページ名: