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

MItamae Hacking Guide

MItamae Hacking Guide

Roppongi.rb #2 Infrastructure x Ruby
http://roppongirb.connpass.com/event/42633/

Takashi Kokubun

November 01, 2016
Tweet

More Decks by Takashi Kokubun

Other Decks in Programming

Transcript

  1. Itamaeͷӡ༻Ͱൃੜͨ͠՝୊ • Itamaeͷ࣮ߦͷͨΊʹrubyΛηοτΞοϓ͠ͳ͚Ε͹ͳͳ͍ • itamae ssh(sshܦ༝ͷద༻)͕஗͍ͷͰαʔόʔଆʹItamaeΛೖΕ࣮ͯߦ͢ Δ • ։ൃ؀ڥͷηοτΞοϓʹ͓͍ͯɺLinuxͩͱruby͕ೖͬͯͳ͍͜ͱ͕͋Δ •

    ItamaeͷͨΊ͚ͩʹrubyͷ؀ڥҰࣜΛύοέʔδϯά͢Δͷ͸໘౗ͩ͠ɺ͔ ͱ͍ͬͯී௨ʹ࢖͏rubyͷ؀ڥ΋Ԛͨ͘͠ͳ͍ • ύοέʔδ͸طʹ͋Δ΋ͷͷɺ࠷ॳ͔ΒγϯάϧόΠφϦͰ࡞ΒΕͨ Itamae͕͋Δͱखܰͦ͏
  2. mruby-cliͱ͸ • https://github.com/hone/mruby-cli • mrubyͰγϯάϧόΠφϦΛ࡞ΔͨΊͷϘΠϥʔϓϨʔτ • ίϚϯυϥΠϯҾ਺ΛmrubyͷArrayʹม׵͠ɺmrubyͰఆٛ͞Εͨ __main__ Λݺͼग़͢Cݴޠͷmainؔ਺ •

    ͜ͷ __main__ ͷ࣮૷͚ͩ͢Ε͹ྑ͍ͷͰɺRubyҎ֎Λॻ͔ͣʹࡁΉ • macOS, Windows޲͚ʹΫϩείϯύΠϧ͢ΔͨΊͷ؀ڥΛ࣋ͭ Dockerfile • ࣮ମ: https://github.com/hone/mruby-cli-docker
  3. MItamae: ΅͕͔͘Μ͕͍͖͑ͨ͞ΐ͏ͷItamae • ruby΍gemʹґଘ͠ͳ͍ͨΊɺόΠφϦΛμ΢ϯϩʔυ͢Δ͚ͩͰଈ࣮ߦՄೳ • CRubyΛ࢖͏৔߹ͱҧͬͯίϯύΠϧࡁͳͷͰɺىಈ͕ߴ଎ • ιʔείʔυΛύʔεͯ͠YARV iseqʹίϯύΠϧ͢Δ·Ͱͷίετ͕ͳ͍ •

    2.5GHz Intel Core i7Ͱɺitamae: 499ms, mitamae: 23ms (21.7ഒ଎) • itamae sshΛαϙʔτ͍ͯ͠ͳ͍ͷͰɺSpecinfra(ඞͣԿΒ͔ͷίϚϯυΛ࢖͏) ͷ͔ΘΓʹී௨ʹCͷؔ਺Λ࢖͏͜ͱͰߴ଎Խ͕Մೳ • Ͳ͏ͤitamae ssh͸஗͍ͷͰɺαʔόʔ΁ͷItamaeͷॳճΠϯετʔϧͱ͔ʹ ͔͠࢖Θͳ͍͠ɺ΍Δʹͯ͠΋ผͷπʔϧʹͯ͠Αͦ͞͏
  4. MItamaeͷεςʔλε • େମͷػೳ͸͋Δ • https://github.com/k0kubun/mitamae#supported-features • fileͷedit, host inventory, verify,

    subscribes(notifies͸͋Δ)͕ͳ͍ • remote_directory, http_request, local_ruby_block ͕ͳ͍ • Arch Linux, CentOS, Debian, Gentoo, macOS, UbuntuΛαϙʔτ • ItamaeຊՈͷ݁߹ςετ͕େମ௨Δ • Travis্ͰDockerίϯςφʹapplyͯ͠ServerspecͰςετͯ͠Δ
  5. ๻ͷMItamaeͷ༻్ • dotfilesͷద༻ • https://github.com/k0kubun/dotfiles • ϨγϐΛࢀߟʹ͍ͨ͠ํ͸ https://github.com/k0kubun/ legacy-dotfiles ΋Ͳ͏ͧ

    • ࣗ୐Ͱ΋ձࣾͰ΋σεΫτοϓϚγϯʹLinuxΛ࢖͍ͬͯΔ͕ɺ ࠷ॳͷηοτΞοϓલʹrubyΛ͍ΕΔඞཁ͕ͳͯ͘ඍົʹॿ͔Δ • ىಈ଎͍͠ɺgem install / bundle install΋ෆཁͩ͠Կ͔ͱָ
  6. defineͨ͠resourceʹωετͨ͠ resource಺Ͱparams͕࢖͑Δ ???? # Itamae ͷ৔߹ define :ruby do version

    = params[:name] execute "..." do not_if "... #{version}" end end ruby '2.3.1'