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

Overview of libspecinfra project

Overview of libspecinfra project

Gosuke Miyashita

November 14, 2017
Tweet

More Decks by Gosuke Miyashita

Other Decks in Technology

Transcript

  1. ࣗݾ঺հ • ٶԼ ߶ี • ߹ಉձࣾServerspec Operations୅ද • ϑϦʔϥϯεͷιϑτ΢ΣΞΤϯδχΞ •

    גࣜձࣾϦΫϧʔτςΫϊϩδʔζATLٕज़ސ໰ • http://mizzy.org/ • mizzy@github, gosukenator@twitter MasterCloud #7 2
  2. Specinfraͱ͸ • Ruby੡ͷϥΠϒϥϦ • OS΍σΟετϦϏϡʔγϣϯຖͷίϚϯυͷҧ͍ͷந৅Խ • ϩʔΧϧɺSSH ܦ༝ɺWinRM ܦ༝ɺDocker API

    ܦ༝ͳͲ ͷίϚϯυ࣮ߦܗࣜͷந৅Խ • ServerspecͷҰ෦ػೳͩͬͨ΋ͷΛ୯ҰͷϥΠϒϥϦͱͯ͠ ಠཱͤͨ͞ MasterCloud #7 7
  3. CentOS 6ͷ৔߹ rpm -q nginx chkconfig --list nginx | grep

    3:on service nginx status MasterCloud #7 9
  4. Ubuntu 14.04ͷ৔߹ dpkg-query -f '${Status}' -W nginx \ | grep

    -E '^(install|hold) ok installed$' ls /etc/rc3.d/ | grep -- '^S..nginx$' \ || grep '^\s*start on' /etc/init/nginx.conf service nginx status \ && service nginx status | egrep 'running|online' MasterCloud #7 11
  5. Serverspecͷ৔߹ describe package('nginx') do it { should be_installed } end

    describe service('nginx') do it { should be_enabled } it { should be_running } end ͲͷOSͰ͋ͬͯ΋ཪͰSpecinfra͕Α͠ͳʹॲཧͯ͘͠ΕΔ MasterCloud #7 12
  6. ServerspecͰͷ࣮ߦܗࣜͷબ୒ʢSSHͰϦϞʔτ࣮ߦʣ set :backend, :ssh host = 'host.example.jp' options = Net::SSH::Config.for(host)

    options[:user] ||= Etc.getlogin set :host, host set :ssh_options, options MasterCloud #7 15
  7. Specinfraొ৔ͷഎܠ • αʔόͷૢ࡞΍৘ใΛऔಘ͢ΔͨΊͷํ๏͸ɺର৅͕ಉ͡Ͱ͋ͬͯ΋ɺOS΍ σΟετϦϏϡʔγϣϯʹΑͬͯҟͳΔ • ύοέʔδͷ৔߹͸ yum ΍ apt-get ͳͲ

    • αʔόૢ࡞΍৘ใऔಘͷ࣮ߦܗࣜ͸ɺର৅ͷαʔό಺Ͱ࣮ߦ͢Δͷ͔ɺ֎͔ Β࣮ߦ͢Δͷ͔ʹΑͬͯ΋ํ๏͕ҟͳΔ • ϩʔΧϧͰ௚઀࣮ߦɺSSHͰϦϞʔτ࣮ߦɺDocker APIܦ༝Ͱ࣮ߦɺͳͲ • ͜ΕΒΛந৅Խ͠ɺҙࣝͤͣʹ֤छOS΍࣮ߦܗࣜʹରԠ͢ΔπʔϧΛ։ൃ͢ ΔͨΊͷج൫ͱͯ͠SpecinfraΛServerspec͔Βಠཱͤͨ͞ MasterCloud #7 18
  8. Specinfraͷ՝୊ • γεςϜ؅ཧܥͷπʔϧ͸ͦΕͧΕಠࣗʹOS/σΟετϦϏϡʔγϣ ϯ΍࣮ߦܗࣜͷந৅ԽΛߦ͓ͬͯΓ࠶ར༻ੑ͕ͳ͍ • Chef, Puppet, Ansible, Itamae(Specinfra) ͳͲ

    • ࠶ར༻ੑΛߟྀͯ͠։ൃͨ͠Specinfra͸ͦΕ΄Ͳ޿͘࢖ΘΕ͍ͯͳ͍ • Specinfra͕RubyͰ͋ΔͨΊɺRubyҎ֎ͷϓϩδΣΫτͰ͸࠾༻Ͱ ͖ͳ͍ • MItamae͸SpecinfraΛmrubyͰ࠶࣮૷͍ͯ͠Δ MasterCloud #7 19
  9. libspecinfraͷݱঢ় • File, Service·ΘΓ࣮૷ࡁ • CentOS 6, 7 • Ubuntu

    14.04, 16.04 • ରԠද: https://github.com/libspecinfra/specinfra#support-matrix • ݴޠόΠϯσΟϯά͸Ruby, mruby, Python͕ଘࡏ • ରԠঢ়گ͸·ͪ·ͪ • libspecinfra/examplesϦϙδτϦʹαϯϓϧίʔυ MasterCloud #7 26
  10. Rustαϯϓϧίʔυʢ௚઀࣮ߦʣ extern crate specinfra; use specinfra::backend; fn main() { let

    b = backend::direct::Direct::new(); let s = specinfra::new(&b).unwrap(); let file = s.file("/etc/passwd"); match file.mode() { Ok(m) => println!("{:o}", m), Err(e) => println!("{}", e), } } MasterCloud #7 27
  11. RustαϯϓϧίʔυʢSSHܦ༝Ͱ࣮ߦʣ extern crate specinfra; use specinfra::backend::ssh::SSHBuilder; fn main() { let

    s = SSHBuilder::new(); let b = s.hostname("localhost").finalize().unwrap(); let s = specinfra::new(&b).unwrap(); let file = s.file("/etc/passwd"); match file.mode() { Ok(m) => println!("{:o}", m), Err(e) => println!("{}", e), } } MasterCloud #7 28
  12. Rubyαϯϓϧίʔυ require 'libspecinfra' require 'libspecinfra/backend/direct' b = Libspecinfra::Backend::Direct::Binding.new() s =

    Libspecinfra::Specinfra::Binding.new(b) f = s.file("/etc/passwd") printf("%#o", f.mode) MasterCloud #7 29
  13. ࢀߟ • libspecinfra • https://github.com/libspecinfra • Serverspecͷ࿦จΛެ։͠·͢ • http://mizzy.org/blog/2014/03/11/1/ •

    libspecinfraϓϩδΣΫτͷ֓ཁͱࠓޙʹ͍ͭͯ • http://atl.recruit-tech.co.jp/blog/4339/ • libspecinfra։ൃऀ޲͚νϡʔτϦΞϧ • http://atl.recruit-tech.co.jp/blog/4349/ MasterCloud #7 33