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

Chef SoloからItamaeに完全移行した話+

Chef SoloからItamaeに完全移行した話+

2015年のitamae meetupで発表した資料です

Tsuyoshi Torii

February 26, 2023
Tweet

More Decks by Tsuyoshi Torii

Other Decks in Technology

Transcript

  1. ࣗݾ঺հ w ௗډɹ߶࢘ !UPSJUPSJΞϧύΧେ໌ਆ  w גࣜձࣾ)"30J% w IUUQXXXIBSPJEDPKQ w

    αʔόΦϖϨʔγϣϯΤϯδχΞ w -VB(PMBOH1ZUIPO/PEFKT1FSM3VCZ w ೋࣇͷ෕
  2. ΞδΣϯμ w ฐࣾͷࣄ৘ w Πϯϑϥ w ։ൃϑϩʔ w ՝୊ w

    $IFG4PMP͔Β*UBNBF΁ͷҠߦ w Ҡߦͨ݁͠Ռ w ·ͱΊ
  3. ։ൃϑϩʔ w ࣄલ४උ w ಠࣗDPOpHʹWN৘ใ௥هOPEFTKTPO࡞Δʜ w ".*࡞੒ w SBLFBXTVQWNWN w

    SBLFBXTQSPWJTJPOWNWN w SBLFBXTTQFDWNWN w SBLFBXTDSFBUF@BNJWNWN w Ϋϥελૢ࡞ w SBLFBXTDGDSFBUF@TUBDLFOWFOW w SBLFBXTDGVQEBUF@TUBDLFOWFOWQBSBNTQBSBNT w SBLFBXTDGEFMFUF@TUBDLFOWFOW
  4. γϯϓϧͳ$IFG # install gem install itamae # ద౰ͳϨγϐ࡞Δ echo "package

    'sl'" > recipe.rb # itamae࣮ߦʢϩʔΧϧϗετʣ itamae local recipe.rb # itamae࣮ߦʢϦϞʔτϗετʣ itamae ssh -u hogeuser -h xxx.xxx.xxx.xxx recipe.rb # itamae࣮ߦʢVagrantʣ itamae ssh --vagrant --host vm_name recipe.rb
  5. γϯϓϧͳ$IFG # attributeΛఆٛͨ͠jsonΛࢦఆ࣮ͯ͠ߦ itamae local -j node.json recipe.rb # ϨγϐΛෳ਺ͭͳ࣮͛ͯߦ

    itamae local recipe01.rb recipe02.rb recipe03.rb # dry-run itamae local --dry-run recipe.rb # ohai৘ใΛࢀর itamae local --ohai recipe.rb
  6. σΟϨΫτϦʗϑΝΠϧߏ଄ ʢ*UBNBFʣ 130+&$5@3005 DPPLCPPLTϓϩδΣΫτݻ༗ΫοΫϒοΫ܈ CBTFDPPLCPPLTڞ௨ΫοΫϒοΫ܈ SPMFTϩʔϧ܈ OPEFTWNຖͷOPEFKTPO WN@BQQKTPO WN@ECKTPO 

    TFDSFUൿີ৘ใ FOUSZQPJOUSC*UBNBF͔Β࣮ߦ͞ΕΔϨγϐͷΤϯτϦϙΠϯτ (FNpMF*UBNBFϓϥάΠϯͳͲͷґଘ͕ॻ͔Εͨ(FNpMF 7BHSBOUpMF7BHSBOUpMF
  7. OPEFTKTPO $IFG4PMP { "td_agent": { "plugins": [ "config-expander", "redeliver", "map",

    "forest", "multi-format-parser" ] }, "environment": "development", "recipes": [ "role[base]", "role[app]", "recipe[td-agent::install]" ] }
  8. OPEFTKTPO *UBNBF { "td_agent": { "plugins": [ "config-expander", "redeliver", "map",

    "forest", "multi-format-parser" ] }, "environment": "environments/development.rb", "recipes": [ "./roles/base.rb", "./roles/app.rb", "./cookbooks/td-agent/install.rb" ] }
  9. FOUSZQPJOUSC # entrypoint.rb # nodes.jsonʹهड़͞Ε͍ͯΔrecipeΛॱ൪ʹಡΉ͚ͩͷϑΝΠϧ node["recipes"] = node["recipes"] || []

    node["recipes"].each do |recipe| include_recipe recipe end # itamae࣮ߦ࣌ʹentrypoint.rbΛࢦఆ itamae local -j node.json entrypoint.rb
  10. #FSLTIFMG(FNpMF # itamae gem 'json' gem 'itamae' gem 'itamae-secrets' #

    plugins gem 'itamae-plugin-recipe-supervisor', \ :github => 'toritori0318/itamae-plugin-recipe-supervisor' gem 'itamae-plugin-recipe-consul', \ :github => 'toritori0318/itamae-plugin-recipe-consul' (FNpMF
  11. JUBNBFTFDSFUT # Πϯετʔϧ gem install itamae-secrets # ϕʔεσΟϨΫτϦΛઃఆϑΝΠϧʹॻ͍ͱ͘ echo 'base:

    ./secret' >> .itamae-secrets.yml # ൿີ伴ੜ੒ > ‘<basedir>/keys/default’ itamae-secrets newkey --method=aes-passphrase (ύεϑϨʔζೖྗ) # ஋อଘ itamae-secrets set itakey itavalue # ஋औಘ itamae-secrets get itakey
  12. FY $POTVMͱ૊Έ߹Θͤͯ ϩʔϧ୯ҐʹϨγϐ࣮ߦ # 1. ֤ϊʔυ͸Πϕϯτwatch͠ͱ͘ consul watch -type event

    -name itamae /path/to/watch_itamae.sh # 2. ϨγϐΛgit(or S3)ʹΞοϓϩʔυ͓ͯ͘͠ # 3. ϓϩϏδϣχϯά͍ͨ͠λΠϛϯάͰeventൃߦ consul event -name itamae -service web 'vm=web recipe=nginx'
  13. XBUDI@FWFOU@JUBNBFTI # ඪ४ೖྗ͔ΒϖΠϩʔυड͚औΓ STDIN_STR=$(cat -) PAYLOAD=`echo $STDIN_STR | jq -r

    '.[0] .Payload' | base64 -d` # key=value ͷ૊Λύʔεͯ͠vm໊΍recipeΛಘΔ (snip) # ϦϙδτϦ(or S3) ͔Βμ΢ϯϩʔυ git clone http://hogehoge/itamae-recipes.git /tmp/itamae-recipes # itamae࣮ߦ itamae local --node-json nodes/${VM}.json ${RECIPE} ˞΍͍ͬͯΔ͜ͱ IUUQTHJTUHJUIVCDPNUPSJUPSJBEBBCDGFBG
  14. ࢀߟ w ࠓճͷϓϩδΣΫτߏ੒αϯϓϧ w ϕʔγοΫ w IUUQTHJUIVCDPNUPSJUPSJJUBNBFTBNQMFQSPKFDU w FOWJSPONFOUTόʔδϣϯ w

    IUUQTHJUIVCDPNUPSJUPSJJUBNBFTBNQMFQSPKFDU USFFFOWJSPONFOUT@WFSTJPO w JUBNBFTFDSFUTόʔδϣϯ w IUUQTHJUIVCDPNUPSJUPSJJUBNBFTBNQMFQSPKFDU USFFJUBNBFTFDSFUTWFSTJPO