Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Ruby tools for Infrastructure Engineer (hbstyle...

Ruby tools for Infrastructure Engineer (hbstyle-2014-0612)

rrreeeyyy

June 13, 2014
Tweet

More Decks by rrreeeyyy

Other Decks in Technology

Transcript

  1. RSpec 4 RSpec is testing tool for the Ruby programming

    language. 4 Ruby ͷςεςΟϯάϑϨʔϜϫʔΫɻ 4 Serverspec ΍ Infrataster ౳ͷ࠷ۙ࿩୊ͷ Infrastructure testing framework Ͱ΋࢖ΘΕ͍ͯΔɻ ࠷ۙ 3.0rc1 ͕ग़ͨɻ
  2. Serverspec Infrastructure testing framework cat spec/target.example.jp/http_spec.rb require 'spec_helper' describe package('httpd')

    do it { should be_installed } end 4 rspec 4 describe, it, its ... ͰςετΛॻ͍͍ͯ͘ 4 http://serverspec.org/resource_types.html
  3. Rakefile require 'rake' require 'rspec/core/rake_task' RSpec::Core::RakeTask.new(:spec) do |t| t.pattern =

    'spec/*/*_spec.rb' end task :default => :spec 4 spec ͱ͍͏໊લͷλεΫ͕ఆٛ͞Ε͍ͯΔ 4 λεΫҰཡ͸ rake -T ͰݟΕΔ
  4. spec_helper.rb 4 ςετͰ࢖͏ڞ௨ͷઃఆΛॻ͘ 4 serverspec Ͱ͸ɺserverspec Ͱ࢖͏ sudo password ΍

    ssh ઌ host ͷఆٛ౳͕ॻ͔Ε͍ͯΔ 4 host = File.basename(Pathname.new(file).dirname) 4 σϑΥϧτͩͱσΟϨΫτϦͷ໊લ͕ϗετ໊ʹͳΔ 8 -rw-r--r-- 1 staff 848 6 12 18:32 spec_helper.rb 0 drwxr-xr-x 3 staff 102 6 12 18:32 target.example.com ← ͜Ε
  5. ςετͷϑΟϧλϦϯά 4 ৭ʑͳঢ়ଶʹΑ͍ͬͯͨ͠/ͨ͘͠ͳ͍ςετ͕͋Δ 4 --tag ΦϓγϣϯΛ࢖͏ 4 --tag <tag_name> 4

    <tag_name> ͷ͍͍ͭͯΔςετͷΈ࣮ߦ͢Δ 4 --tag ~<tag_name> 4 <tag_name> ͷ͍͍ͭͯΔςετΛআ֎͢Δ 4 ଞʹ΋৭ʑग़དྷΔ