Slide 1

Slide 1 text

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

Slide 2

Slide 2 text

ࣗݾ঺հ • ٶԼ ߶ี • ߹ಉձࣾServerspec Operations୅ද • ϑϦʔϥϯεͷιϑτ΢ΣΞΤϯδχΞ • גࣜձࣾϦΫϧʔτςΫϊϩδʔζATLٕज़ސ໰ • http://mizzy.org/ • mizzy@github, gosukenator@twitter MasterCloud #7 2

Slide 3

Slide 3 text

ஶॻɾ؂༁ॻ MasterCloud #7 3

Slide 4

Slide 4 text

libspecinfraͱ͸ MasterCloud #7 4

Slide 5

Slide 5 text

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

Slide 6

Slide 6 text

Specinfraͱ͸ MasterCloud #7 6

Slide 7

Slide 7 text

Specinfraͱ͸ • Ruby੡ͷϥΠϒϥϦ • OS΍σΟετϦϏϡʔγϣϯຖͷίϚϯυͷҧ͍ͷந৅Խ • ϩʔΧϧɺSSH ܦ༝ɺWinRM ܦ༝ɺDocker API ܦ༝ͳͲ ͷίϚϯυ࣮ߦܗࣜͷந৅Խ • ServerspecͷҰ෦ػೳͩͬͨ΋ͷΛ୯ҰͷϥΠϒϥϦͱͯ͠ ಠཱͤͨ͞ MasterCloud #7 7

Slide 8

Slide 8 text

OS/σΟετϦϏϡʔγϣϯຖͷίϚϯυͷҧ͍ͷந৅Խ • ྫͱͯ͠ҎԼͷ͜ͱΛ֬ೝ͢Δ͜ͱΛߟ͑Δ • nginxύοέʔδ͕Πϯετʔϧ͞Ε͍ͯΔ • nginxαʔϏε͕ࣗಈىಈ͢ΔΑ͏ʹͳ͍ͬͯΔ • nginx͕ىಈ͍ͯ͠Δ MasterCloud #7 8

Slide 9

Slide 9 text

CentOS 6ͷ৔߹ rpm -q nginx chkconfig --list nginx | grep 3:on service nginx status MasterCloud #7 9

Slide 10

Slide 10 text

CentOS 7ͷ৔߹ rpm -q nginx systemctl is-enabled nginx systemctl is-active nginx MasterCloud #7 10

Slide 11

Slide 11 text

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

Slide 12

Slide 12 text

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

Slide 13

Slide 13 text

࣮ߦܗࣜͷҧ͍ͷந৅Խ • ର৅ͷϗετ্Ͱ௚઀࣮ߦ • SSHͰϦϞʔτ࣮ߦ • WinRMͰϦϞʔτ࣮ߦ • Docker APIͰίϯςφ಺Ͱ࣮ߦ • ͳͲ MasterCloud #7 13

Slide 14

Slide 14 text

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

Slide 15

Slide 15 text

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

Slide 16

Slide 16 text

Specinfraͱ͸ʢ·ͱΊʣ • Serverspec͔Β೿ੜͨ͠Ruby੡ͷϥΠϒϥϦ • OS΍σΟετϦϏϡʔγϣϯຖͷίϚϯυͷҧ͍ͷந৅Խ • ʮԿΛ࣮ߦ͢Δ͔ʯΛந৅Խ • ϩʔΧϧɺSSH ܦ༝ɺWinRM ܦ༝ɺDocker API ܦ༝ͳͲͷ ίϚϯυ࣮ߦܗࣜͷந৅Խ • ʮͲ͏࣮ߦ͢Δ͔ʯΛந৅Խ MasterCloud #7 16

Slide 17

Slide 17 text

Specinfraొ৔ͷ എܠͱ՝୊ MasterCloud #7 17

Slide 18

Slide 18 text

Specinfraొ৔ͷഎܠ • αʔόͷૢ࡞΍৘ใΛऔಘ͢ΔͨΊͷํ๏͸ɺର৅͕ಉ͡Ͱ͋ͬͯ΋ɺOS΍ σΟετϦϏϡʔγϣϯʹΑͬͯҟͳΔ • ύοέʔδͷ৔߹͸ yum ΍ apt-get ͳͲ • αʔόૢ࡞΍৘ใऔಘͷ࣮ߦܗࣜ͸ɺର৅ͷαʔό಺Ͱ࣮ߦ͢Δͷ͔ɺ֎͔ Β࣮ߦ͢Δͷ͔ʹΑͬͯ΋ํ๏͕ҟͳΔ • ϩʔΧϧͰ௚઀࣮ߦɺSSHͰϦϞʔτ࣮ߦɺDocker APIܦ༝Ͱ࣮ߦɺͳͲ • ͜ΕΒΛந৅Խ͠ɺҙࣝͤͣʹ֤छOS΍࣮ߦܗࣜʹରԠ͢ΔπʔϧΛ։ൃ͢ ΔͨΊͷج൫ͱͯ͠SpecinfraΛServerspec͔Βಠཱͤͨ͞ MasterCloud #7 18

Slide 19

Slide 19 text

Specinfraͷ՝୊ • γεςϜ؅ཧܥͷπʔϧ͸ͦΕͧΕಠࣗʹOS/σΟετϦϏϡʔγϣ ϯ΍࣮ߦܗࣜͷந৅ԽΛߦ͓ͬͯΓ࠶ར༻ੑ͕ͳ͍ • Chef, Puppet, Ansible, Itamae(Specinfra) ͳͲ • ࠶ར༻ੑΛߟྀͯ͠։ൃͨ͠Specinfra͸ͦΕ΄Ͳ޿͘࢖ΘΕ͍ͯͳ͍ • Specinfra͕RubyͰ͋ΔͨΊɺRubyҎ֎ͷϓϩδΣΫτͰ͸࠾༻Ͱ ͖ͳ͍ • MItamae͸SpecinfraΛmrubyͰ࠶࣮૷͍ͯ͠Δ MasterCloud #7 19

Slide 20

Slide 20 text

՝୊ղܾͷͨΊͷ ఏҊͱ࣮૷ MasterCloud #7 20

Slide 21

Slide 21 text

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

Slide 22

Slide 22 text

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

Slide 23

Slide 23 text

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

Slide 24

Slide 24 text

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

Slide 25

Slide 25 text

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

Slide 26

Slide 26 text

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

Slide 27

Slide 27 text

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

Slide 28

Slide 28 text

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

Slide 29

Slide 29 text

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

Slide 30

Slide 30 text

mrubyαϯϓϧίʔυ b = Libspecinfra::Backend::Direct.new() s = Libspecinfra::Specinfra.new(b) f = s.file("/etc/passwd") printf("%#o", f.mode) MasterCloud #7 30

Slide 31

Slide 31 text

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

Slide 32

Slide 32 text

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

Slide 33

Slide 33 text

ࢀߟ • 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