Overview of libspecinfra project

Overview of libspecinfra project

0d5d8fb9cc4c06f581825f5a61d3f5f1?s=128

Gosuke Miyashita

November 14, 2017
Tweet

Transcript

  1. libspecinfraͷ ֓ཁͱݱঢ়ͱࠓޙ MasterCloud #7 1

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

    גࣜձࣾϦΫϧʔτςΫϊϩδʔζATLٕज़ސ໰ • http://mizzy.org/ • mizzy@github, gosukenator@twitter MasterCloud #7 2
  3. ஶॻɾ؂༁ॻ MasterCloud #7 3

  4. libspecinfraͱ͸ MasterCloud #7 4

  5. libspecinfraͱ͸ • Specinfraͷ֦ு/࠶࣮૷ϓϩδΣΫτ MasterCloud #7 5

  6. Specinfraͱ͸ MasterCloud #7 6

  7. Specinfraͱ͸ • Ruby੡ͷϥΠϒϥϦ • OS΍σΟετϦϏϡʔγϣϯຖͷίϚϯυͷҧ͍ͷந৅Խ • ϩʔΧϧɺSSH ܦ༝ɺWinRM ܦ༝ɺDocker API

    ܦ༝ͳͲ ͷίϚϯυ࣮ߦܗࣜͷந৅Խ • ServerspecͷҰ෦ػೳͩͬͨ΋ͷΛ୯ҰͷϥΠϒϥϦͱͯ͠ ಠཱͤͨ͞ MasterCloud #7 7
  8. OS/σΟετϦϏϡʔγϣϯຖͷίϚϯυͷҧ͍ͷந৅Խ • ྫͱͯ͠ҎԼͷ͜ͱΛ֬ೝ͢Δ͜ͱΛߟ͑Δ • nginxύοέʔδ͕Πϯετʔϧ͞Ε͍ͯΔ • nginxαʔϏε͕ࣗಈىಈ͢ΔΑ͏ʹͳ͍ͬͯΔ • nginx͕ىಈ͍ͯ͠Δ MasterCloud

    #7 8
  9. CentOS 6ͷ৔߹ rpm -q nginx chkconfig --list nginx | grep

    3:on service nginx status MasterCloud #7 9
  10. CentOS 7ͷ৔߹ rpm -q nginx systemctl is-enabled nginx systemctl is-active

    nginx MasterCloud #7 10
  11. 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
  12. 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
  13. ࣮ߦܗࣜͷҧ͍ͷந৅Խ • ର৅ͷϗετ্Ͱ௚઀࣮ߦ • SSHͰϦϞʔτ࣮ߦ • WinRMͰϦϞʔτ࣮ߦ • Docker APIͰίϯςφ಺Ͱ࣮ߦ

    • ͳͲ MasterCloud #7 13
  14. ServerspecͰͷ࣮ߦܗࣜͷબ୒ʢ௚઀࣮ߦʣ # UnixܥOSͷ৔߹ set :backend, :exec # Windowsͷ৔߹ set :backend,

    :cmd MasterCloud #7 14
  15. 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
  16. Specinfraͱ͸ʢ·ͱΊʣ • Serverspec͔Β೿ੜͨ͠Ruby੡ͷϥΠϒϥϦ • OS΍σΟετϦϏϡʔγϣϯຖͷίϚϯυͷҧ͍ͷந৅Խ • ʮԿΛ࣮ߦ͢Δ͔ʯΛந৅Խ • ϩʔΧϧɺSSH ܦ༝ɺWinRM

    ܦ༝ɺDocker API ܦ༝ͳͲͷ ίϚϯυ࣮ߦܗࣜͷந৅Խ • ʮͲ͏࣮ߦ͢Δ͔ʯΛந৅Խ MasterCloud #7 16
  17. Specinfraొ৔ͷ എܠͱ՝୊ MasterCloud #7 17

  18. Specinfraొ৔ͷഎܠ • αʔόͷૢ࡞΍৘ใΛऔಘ͢ΔͨΊͷํ๏͸ɺର৅͕ಉ͡Ͱ͋ͬͯ΋ɺOS΍ σΟετϦϏϡʔγϣϯʹΑͬͯҟͳΔ • ύοέʔδͷ৔߹͸ yum ΍ apt-get ͳͲ

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

    • ࠶ར༻ੑΛߟྀͯ͠։ൃͨ͠Specinfra͸ͦΕ΄Ͳ޿͘࢖ΘΕ͍ͯͳ͍ • Specinfra͕RubyͰ͋ΔͨΊɺRubyҎ֎ͷϓϩδΣΫτͰ͸࠾༻Ͱ ͖ͳ͍ • MItamae͸SpecinfraΛmrubyͰ࠶࣮૷͍ͯ͠Δ MasterCloud #7 19
  20. ՝୊ղܾͷͨΊͷ ఏҊͱ࣮૷ MasterCloud #7 20

  21. ՝୊Λղܾ͢ΔͨΊͷఏҊ • Specinfra͕୲͍ͬͯΔ • OS/σΟετϦϏϡʔγϣϯͷந৅Խ • ࣮ߦܗࣜͷந৅Խ • ͜ΕΒΛ༷ʑͳݴޠ͔Β΋ར༻Ͱ͖Δڞ༗ϥΠϒϥϦͱͯ͠ ఏڙ͢Δ

    MasterCloud #7 21
  22. ఏҊΛ࣮ݱ͢ΔͨΊͷ࣮૷ • ͦͷ࣮૷Λ୲͏ͷ͕libspecinfraϓϩδΣΫτ • libspecinfraϓϩδΣΫτ͸࣍ͷΑ͏ͳOSS͔Βߏ੒͞ΕΔ • ڞ༗ϥΠϒϥϦΛఏڙ͢ΔSpecinfraίΞ(RustͰ࣮૷) • SpecinfraίΞ͕ఏڙ͢Δڞ༗ϥΠϒϥϦΛݺͼग़ͨ͢Ί ͷ֤ݴޠ༻όΠϯσΟϯά

    • https://github.com/libspecinfra MasterCloud #7 22
  23. ͳͥRustͰ࣮૷ͨ͠ͷ͔ • ʮڞ༗ϥΠϒϥϦΛఏڙ͢Δʯͱ͍͏໨తͳΒଞʹC΍C++ • ৽͘͠ϓϩδΣΫτΛ࢝ΊΔͳΒRust͔ͳɺͱ • Cݴޠͱͷ਌࿨ੑʢ㲈ଞݴޠͱͷ਌࿨ੑʣ • mruby΍libffi౳ͱܨ͗΍͍͢ •

    RustΛ֮͑ͯΈ͔ͨͬͨ MasterCloud #7 23
  24. libspecinfraͱ͸ʢ·ͱΊʣ • Specinfra͕࣋ͭ՝୊Λղܾ͢ΔͨΊʹ࢝ΊͨϓϩδΣΫτ • OS/σΟετϦϏϡʔγϣϯͷந৅Խɺ࣮ߦܗࣜͷந৅Խͷ ͨΊͷڞ༗ϥΠϒϥϦΛఏڙʢRustͰ࣮૷ʣ • ڞ༗ϥΠϒϥϦΛར༻͢ΔͨΊͷ֤छݴޠόΠϯσΟϯά΋ ఏڙ MasterCloud

    #7 24
  25. libspecinfraͷ ݱঢ়ͱࠓޙ MasterCloud #7 25

  26. 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
  27. 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
  28. 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
  29. 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
  30. mrubyαϯϓϧίʔυ b = Libspecinfra::Backend::Direct.new() s = Libspecinfra::Specinfra.new(b) f = s.file("/etc/passwd")

    printf("%#o", f.mode) MasterCloud #7 30
  31. libspecinfra ͕໨ࢦ͢ͱ͜Ζ • γεςϜͷӡ༻؅ཧ͕ෳࡶԽ͍ͯ͘͠தͰɺͦΕΛղܾ͢Δ ΑΓྑ͍πʔϧ͕ੜ·ΕΔͷΛࢧԉ͢Δ • ίϯςφ΍ϢχΧʔωϧͱ͍ͬͨ৽͍͠αʔόܗ͕ࣜग़͖ͯ ͯ΋ɺطଘͷπʔϧ͕؆୯ʹରԠͰ͖ΔΑ͏ʹ͢Δ • ࠓޙੜ·ΕΔγεςϜ؅ཧܥπʔϧ͢΂ͯͷج൫ͱͳΔ

    MasterCloud #7 31
  32. ڠྗऀઈࢍืूத • ࣮ӡ༻Ͱ࢖ͬͯΈ͍ͨͱ͍͏ਓ • ࣮ӡ༻Ͱ͜͏࢖͑ΔͷͰ͸ͱ͍͏ΞΠσΞ • ଞݴޠόΠϯσΟϯά։ൃͯ͘͠ΕΔਓ • ֤छOS΍ϦιʔεରԠͯ͘͠ΕΔਓ •

    Rustৄ͍͠ਓ MasterCloud #7 32
  33. ࢀߟ • 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