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

Start Infrastructure as Code with Ansible and Serverspec

D6fc8a819afa94f464fe322032a6687f?s=47 Mahito
June 16, 2015

Start Infrastructure as Code with Ansible and Serverspec

とある勉強会で使った、最近流行りのInfrastructure as CodeをAnsibleとServerspecを用いて簡単に解説した際の資料です。

D6fc8a819afa94f464fe322032a6687f?s=128

Mahito

June 16, 2015
Tweet

Transcript

  1. "OTJCMFͱ4FSWFSTQFD Ͱ͸͡ΊΔ *OGSBTUSVDUVSFBT$PEF

  2. ͩΕʁ ໊લ .BIJUP0(63" *% !.BIJUP ΍ͬͯΔ͜ͱɿ
  0QFO4UBDL ΍͖ͬͯͨ͜ͱ
 

    3VCZʢ3VCZձٞϘϥϯςΟΞελοϑʣ
  Ϋϥ΢υʢ*BB4 ,7. "84ʣ
  ෼ࢄॲཧج൫ʢ.POHP%# $BTTBOESB )#BTF )BEPPQʣ
  ࣗಈԽ $IFG "OTJCMF 'BCSJD 4FSWFSTQFD 7BHSBOU
  3. ࠓ೔࿩͢͜ͱ w *OGSBTUSVDUVSFBT$PEFͱͦͷഎܠ w ߏ੒ࣗಈ؅ཧπʔϧʮ"OTJCMFʯ w αʔόঢ়ଶ֬ೝπʔϧʮ4FSWFSTQFDʯ

  4. ैདྷͷαʔόߏங αʔό৬ਓͷே͸ૣ͍ɻϕϯμ͔Β࢓ೖΕͨ৽઱ ͳαʔόʹ࡞ۀखॱॻΛݟͳ͕Β04΍ύοέʔδ ͷΠϯετʔϧɺύϥϝʔλΛઃఆͯ͠ΞϓϦ έʔγϣϯΛ͓ܴ͑͢Δͷͩɻʮ৽઱ͳαʔό͸ ΍ͬͺΓҧ͍·͢Ͷɺίϯιʔϧ͔Βͷ൓Ԡ΋ए ׯૣ͘ײ͡·͢ɻʯϕςϥϯαʔό৬ਓ͸ޠΔɻ ϕςϥϯ͕ࢧ͑Δʢ͈́

  5. ! ! ɹɹɹɹɹɹɹɹɹʊʊʊ ɹɹɹɹɹɹɹʗ˶ɹɹ˶ʘ ɹɹɹɹɹʗɹʢ˶ʣɹʢ˶ʣʘɹɹɹ҆ՁͰେྔͷαʔό͕ ɹɹɹɹʗɹʢ@@ਓ@@ʣʘɹɹखʹೖ͓ͬͨʂʂʂʂʂ ɹɹɹcɹɹVɹA:˶Zɹɹɹc ɹɹɹʘɹɹɹƄʔ˄ɹɹ ʗ ɹɹɹɹ˶ʋɹɹʔɹɹŎʋ

    ɹɹɹSŖʍɹɹɹɹɹɹɹʒʋ ɹɹɹɹ ůʌɹ ɹɹɹɹɹɹʌ@ϊ c ɹɹɹɹcɹʋʒɹɹɹɹɹɹɹɹcɹc Ϋϥ΢υͷొ৔
  6. ! ɹɹɹɹɹɹʊʊʊ@ ɹɹɹɹɹʗɹɹɹɹʘ ɹɹɹɹʗɹ@ϊɹʋŊ@ɹʘ ɹɹʗɹPƅ˶ɹɹɹ˶ƅPɹʘɹࠓ೔΋·ͨɺαʔόͷߏஙͱ ɹɹcɹɹɹɹʢ@@ਓ@@ʣɹɹɹɹcɹઃఆͷ࢓ࣄ͕࢝·Δ͓ʜ ɹɹʘɹɹɹʆ˶ɹɹʗɹ େྔͷαʔόߏஙͱઃఆ

  7. ͱͳΔ·͑ʹ ࣗಈԽ͠·͠ΐ͏

  8. *OGSBTUSVDUVSFBT$PEF w ίʔυʹΑΔΠϯϑϥߏஙͷࣗಈԽ $MPVEPS7. *NBHF -BVODI 04 *OTUBMM 4ZTUFN$POpHVSBUJPO "QQMJDBUJPO4FSWJDF

    %FQMPZNFOU w ,JDLTUBSU w $PCCMFS w +VNQTUBSU w 0QFO23. w "84 w 9FO w ,7. w 7.XBSF w $IFG w 1VQQFU w $BQJTUSBOP w 'BCSJD w 'VOD 0SDIFTUSBUJPO $POpHVSBUJPO #PPUTUSBQQJOH 1SPWJTJPOJOH"DUJWJUZ ग़యIUUQFOPSFJMMZDPNWFMPDJUZNBSQVCMJDTDIFEVMFEFUBJM
  9. ίʔυԽͷϝϦοτ w ैདྷͷιϑτ΢ΣΞͷ։ൃελΠϧ͕࢖͑Δ w όʔδϣϯ؅ཧ΍ϨϏϡʔ͕Ͱ͖Δ w ୭͕ಈ͔ͯ͠΋ಉ݁͡ՌʹͳΔ w ࡞ۀखॱॻʹΑΔਓҝϛε͕ى͖ͳ͍ w

    $*ͰͷࣗಈςετσϓϩΠ͕Ͱ͖Δ
  10. None
  11. "OTJCMF w 1ZUIPO੡ͷࣗಈԽπʔϧ w "OTJCMF͕ࣾத৺ͱͳͬͯ։ൃ͍ͯ͠Δ044 w (JUIVC্Ͱ֬ೝ͢Δͱ೥݄ʹW͕Ϧ Ϧʔεɻݱࡏ͸Y͕࠷৽ɻ΋͏͙͢W w ϦϦʔε଎౓͸ૣ͘࠷୹೔Ͱ௕ͯ͘΋ϲ݄

  12. "OTJCMFͷಛ௃ "OTJCMFJTUIFTJNQMFTUXBZUPBVUPNBUF w 4JNQMF
 "VUPNBUFJOIPVSTOPUXFFLTXJUI"OTJCMFTIVNBOSFBEBCMF*5 BVUPNBUJPOMBOHVBHF w "HFOUMFTT
 "OTJCMFVTFT44)JOTUFBEPGBHFOUT.PSFF⒏DJFOU NPSFTFDVSFBOEMFTT

    UPNBOBHF w 1PXFSGVM
 "QQEFQMPZNFOU DPOpHVSBUJPONBOBHFNFOUBOEPSDIFTUSBUJPOBMMGSPN POFTZTUFN ग़యIUUQXXXBOTJCMFDPN
  13. 4JNQMF w هड़͕:".-ܗࣜͳͷͰਓ͕ಡΈ΍͍͢  IPTUTXFCTFSWFST TFSJBMVQEBUFNBDIJOFTBUBUJNF SPMFT DPNNPO XFCBQQ !

    IPTUTEC@TFSWFST UBTLT OBNF.Z42-*OTUBMM BQUOBNFNZTRMTFSWFSTUBUFQSFTFOU
  14. "HFOUMFTT w 44)Λ࢖ͬͯର৅αʔόʹ௚઀ΞΫηε͢Δͨ ΊΤʔδΣϯτ͕ෆཁ w ͓٬༷؀ڥͰ"HFOU͕ೖΕΒΕͳ͍ʢ4*FSͷ೰Έʣ w ର৅͕/8ػثͰBHFOU͕ೖΒͳ͍ʢ/8԰ͷ೰Έʣ w ϓϥάΠϯʹΑΓ44)Ҏ֎ͷ1SPUDPM΋࢖༻Մೳ

    w 8JO3.Ͱ8JOEPXTͷૢ࡞΋Մೳ
  15. 1PXFSGVM w 0SDIFTUSBUJPOͱ$POpHVSBUJPOΛΧόʔ $MPVEPS7. *NBHF -BVODI 04 *OTUBMM 4ZTUFN$POpHVSBUJPO "QQMJDBUJPO4FSWJDF

    %FQMPZNFOU w ,JDLTUBSU w $PCCMFS w +VNQTUBSU w 0QFO23. w "84 w 9FO w ,7. w 7.XBSF w $IFG w 1VQQFU w $BQJTUSBOP w 'BCSJD w 'VOD 0SDIFTUSBUJPO $POpHVSBUJPO #PPUTUSBQQJOH 1SPWJTJPOJOH"DUJWJUZ "OTJCMF ग़యIUUQFOPSFJMMZDPNWFMPDJUZNBSQVCMJDTDIFEVMFEFUBJM
  16. (PPHMF5SFOET ग़యɿIUUQHPPHM-*+B6

  17. 2 ίʔυͰࣗಈԽ͢ΔͳΒγΣϧε ΫϦϓτͰ΋͍͍Μ͡Όͳ͍ͷʁ

  18. "γΣϧεΫϦϓτ͸ ႈʢ΂͖ʣ౳ੑΛอূͯ͘͠Ε·ͤΜ IPHFTI IPHFDPOGͷ຤ඌʹ)PHFΛ௥Ճ FDIP)PHFIPHFDPOG CBTIIPHFTI CBTIIPHFTI UBJMIPHFDPOG )PHF )PHF

  19. ৘ใ޻ֶʹ͓͚Δႈ౳ੑ 8JLJQFEJBʹΑΔͱ
 l͋Δૢ࡞Λ౓ߦͬͯ΋ෳ਺ճߦͬͯ΋ಉ͡ޮՌ ͱͳΔ͜ͱΛݴ͏ɻಛʹɺԿճߦͬͯ΋Τϥʔ΍ ෆ੔߹ͷঢ়ଶ͕มΘΒͳ͍ૢ࡞Λࢦ͢ɻz ! γΣϧεΫϦϓτͷ৔߹ႈ౳ੑΛอূ͢ΔͨΊʹ͸ࣗ෼Ͱႈ ౳ੑΛ୲อͨ͠ίʔυΛॻ͘ඞཁ͕͋Δ͕ "OTJCMF͸ႈ౳ੑΛอূ͢ΔػೳΛ͍࣋ͬͯΔ ஫ɿႈ౳ੑΛ͍࣋ͬͯͳ͍ػೳ΋͋Γ·͢

  20. "OTJCMFʹΑΔ ίʔυԽͷϝϦοτ w ैདྷͷιϑτ΢ΣΞͷ։ൃελΠϧ͕࢖͑Δ w όʔδϣϯ؅ཧ΍ϨϏϡʔ͕Ͱ͖Δ w ႈ౳ੑͷػೳΛ࢖͑͹୭͕Կ౓ಈ͔ͯ͠΋ಉ݁͡ՌʹͳΔ ㅟ ㅟ

    w ࡞ۀखॱॻʹΑΔਓҝϛε͕ى͖ͳ͍ w ৗʹಉ͡؀ڥ͕ߏங͞ΕΔ ㅟ ㅟ ㅟ ㅟ ㅟ ㅟ ㅟ ㅟ ㅟ ㅟ ㅟ ㅟ w $*ͰͷࣗಈςετσϓϩΠ͕Ͱ͖Δ
  21. *OTUBMM w .BD CSFXVQEBUF
 CSFXJOTUBMMBOTJCMF w QJQ TVEPFBTZ@JOTUBMMQJQ
 TVEPQJQJOTUBMMBOTJCMF

  22. "OTJCMFͷ࣮ߦ w BOTJCMFίϚϯυ w ίϚϯυϥΠϯͰͷ"OTJCMFͷ࣮ߦ BOTJCMFI
 6TBHFBOTJCMFIPTUQBUUFSO<PQUJPOT>
 ʜ
 BOTJCMFBMMJMPDBMIPTU DMPDBMNQJOH


    IPTUcTVDDFTT\
 DIBOHFEGBMTF 
 QJOHQPOH
 ^
  23. "OTJCMFͷ࣮ߦ w BOTJCMFQMBZCPPLίϚϯυ w 1MBZCPPLΛ༻͍ͨ"OTJCMFͷ࣮ߦ BOTJCMFQMBZCPPLI
 6TBHFBOTJCMFQMBZCPPLQMBZCPPLZNM
 ʜ
 BOTJCMFQMBZCPPLJIPTUTQJOHZNM
 1-":<IPTU>

    
 ("5)&3*/('"$54 
 PL<IPTU>
 5"4,<1JOH> 
 PL<IPTU>
 1-":3&$"1 
 IPT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SWJDFJTOPUIBQQZ XIFO"8&40.&OPUJOXFCQBHFDPOUFOU
  28. "OTJCMFͷςετ͸NPEVMFͷಈ࡞֬ೝ ! αʔό͕࢓༷௨ΓʹߏஙͰ͖͔ͨͷݕূ͸ʁ

  29. IUUQTFSWFSTQFDPSH

  30. 4FSWFSTQFDͷಛ௃ w 3VCZͷςετϑϨʔϜϫʔΫ34QFDΛϕʔεʹ͠ ͨαʔόͷঢ়ଶࢼݧπʔϧ w ϩʔΧϧϞʔυɺ44)ɺ8JO3.ɺ%PDLFS"1*౳ Ͱର৅ͷαʔόͰίϚϯυΛ࣮ߦ͠αʔόͷঢ়ଶ ͕ҙਤͨ͠ঢ়ଶʹͳ͍ͬͯΔ͔Λ֬ೝ͢Δɻ w "OTJCMFͱಉ༷ʹ"HFOUMFTTͳ͘͠Έ

    w $IFG 1VQQFU "OTJCMF౳ͷπʔϧʹґଘ͠ͳ͍
  31. *OTUBMM w (FN HFNJOTUBMMŠOPSEPDŠOPSJTFSWFSTQFD w CVOEMF HFNJOTUBMMŠOPSJŠOPSEPDCVOEMFS
 CVOEMFJOJU
 WJN(FNpMF
 HFNbTFSWFSTQFD`


    CVOEMFJOTUBMMŠQBUIWFOEPSCVOEMF
  32. TFSWFSTQFDͷ࣮ߦ w CVOEMFͷ৔߹͸࠷ॳʹ`CVOEMFFYFD`Λ͚ͭΔ TFSWFSTQFDJOJU
 TFSWFSTQFDJOJUͰ൒ࣗಈతʹઃఆ΍αϯϓϧ͕ੜ੒͞ΕΔ SBLF

  33. αϯϓϧ

  34. 3FTPVSDF5ZQFT w 4FSWFSTQFDͰ͸֬ೝ͢Δ֤छϦιʔε͕༻ҙ͞ Ε͍ͯΔɻ w FYDPNNBOE pMF LFSOFM@NPEVMF FUD w

    ࢀরɿ
 IUUQTFSWFSTQFDPSHSFTPVSDF@UZQFTIUNM
  35. 5%% ςετۦಈ։ൃ
 ࠷ॳʹςετΛهड़͠ɺهड़ͨ͠ςετΛ௨Δ࣮ ૷Λߦ͏͜ͱͰ࠷খݶͷಈ͘ػೳΛอূ͠ͳ͕Β ࡞Δɻ

  36. αʔόߏஙͰͷ5%% αʔόͷঢ়ଶΛઌʹఆٛ͠ɺͦͷঢ়ଶʹͳΔΑ͏ ʹ$IFG 1VQQFU "OTJCMFͷίʔυΛهड़͢Δ

  37. ·ͱΊ w "OTJCMF͸"HFOUMFTTͰ͋Γɺ༷ʑͳϞδϡʔϧ͕ ༻ҙ͞Ε͓ͯΓɺ:".-Λॻ͚ͩ͘Ͱ؆୯ʹߏங͕ Ͱ͖Δ w 4FSWFSTQFD͸"HFOUMFTT͔ͭɺߏஙπʔϧʹґଘ ͤͣʹαʔόͷঢ়ଶ֬ೝΛ͢Δ͜ͱ͕Ͱ͖Δ w *OGSBTUSVDUVSFBT$PEFʹΑΓɺ


    Πϯϑϥͷࣗಈߏங΍όʔδϣϯ؅ཧ΍ϨϏϡʔɺ 5%%ͳͲɺैདྷͷ։ൃख๏͕Ͱ͖Δ