[[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-39') }
 end

*サービス [#vfdec1d0]
***chkconfigが有効になっているかとサービスが起動しているかの書き方 [#hcb1c383]
 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\ httpd\ \|\ grep\ 3:on

***サービスが稼働していなかった場合のエラー内容 [#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\ status
       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\ \|\ grep\ --\ :80\\\

***コマンドを実行してその標準出力の結果をチェック [#h4eb6180]
 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

トップ   編集 差分 履歴 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS