Infrastructure as (Ruby) Code の現状確認 / Infrastructure as Ruby Code 2016

5919537a0ecfa5d4dea704cf878ae90e?s=47 toshimaru
November 02, 2016

Infrastructure as (Ruby) Code の現状確認 / Infrastructure as Ruby Code 2016

Roppongi.rb #2 "Infrastructure x Ruby" ( http://roppongirb.connpass.com/event/42633/ )での発表スライドです。

- Blog記事にもまとめてあります: http://blog.toshimaru.net/infrastructure-as-ruby-code-2016/

5919537a0ecfa5d4dea704cf878ae90e?s=128

toshimaru

November 02, 2016
Tweet

Transcript

  1. *OGSBTUSVDUVSFBT 3VCZ $PEF ͷݱঢ়֬ೝ 3PQQPOHJSC

  2. TFMGJOUSPEVDUJPO UPTIJNBSV UPTIJNBSV@F 3BJMT%FWFMPQFS 3PQQPOHJSC0SHBOJTFS 5PTIJNBSV

  3. ΞδΣϯμ w *OGSBTUSVDUVSFBT$PEFͷҙٛ w ߏ੒؅ཧπʔϧͷྺ࢙ͱ෼ྨ w *OGSBTUSVDUVSFBT$PEFͷΧόʔൣғ w $POpHVSBUJPOBT$PEF

  4. *OGSBTUSVDUVSFBT$PEFͷҙٛ  ΠϯϑϥߏஙखॱΛൿ఻ͷλϨԽͤ͞ͳ͍  खॱΛίʔυʹམͱͯ͠Πϯϑϥ΁ͷมߋΛτ ϥοΩϯά͢Δ  खॱΛෆมʢJNNVUBCMFʣʹ͢Δ

  5. ൿ఻ͷλϨ

  6. ൿ఻ͷλϨ w ·ΔͰൿ఻ͷλϨͷΑ͏ʹܧ͗଍͠ܧ͗଍͠มߋ͕ ೖΓ୅ʑड͚ܧ͕Ε͖ͯͨαʔόʔ w ϝϯςφϯε͞Ε͍ͯΔ͔Ͳ͏͔·ΔͰΘ͔Βͳ͍ ʮαʔόʔߏஙखॱॻYMTʯ w Πϯϑϥ୲౰ऀͷΞλϚʹ͔͠ೖ͍ͬͯͳ͍Ӆ͠ຯ ʘ

    ?P? ʗ
  7. ΠϯϑϥετϥΫνϟʔ ΛίʔυԽ͢Δ

  8. ίʔυԽ͢Δͱ͍͏͜ͱ w ίʔυԽ͞ΕΔ w ➜(JUͰτϥοΫՄೳʹͳΔ w ➜(JUIVCͰϓϧϦΫՄೳʹͳΔ w ➜(JUIVCͰϨϏϡʔՄೳʹͳΔ w

    ➜ (JU)VC8PSLqPX
  9. *NNVUBCMF *OGSBTUSVDUVSF

  10. r$IBE'PXMFS  l5SBTI:PVS4FSWFSTBOE#VSO:PVS$PEF*NNVUBCMF *OGSBTUSVDUVSFBOE%JTQPTBCMF$PNQPOFOUTz

  11. *NNVUBCMF*OGSBTUSVDUVSF ,FZXPSET w *NNVUBCMFʢෆมʣ w %JTQPTBCMFʢ࢖͍ࣺͯʣ w 3FQSPEVDJCMFʢ࠶ݱՄೳʣ w *EFNQPUFODFʢႈ౳ੑʣ

  12. *NNVUBCMF*OGSBTUSVDUVSF w "84 ($1Λ࢝Ίͱ͢Δ*BB4ొ৔ʹΑΓμΠφϛοΫͳ αʔόʔߏ੒͕Մೳͱͳͬͨ w Ϙλϯ̍ͭͰ্͛Լ͛͢Δαʔόʔ %JTQPTBCMFͳ αʔόʔ ஀ੜ

    w ΦʔτεέʔϦϯάͷԸܙΛڗड͢ΔͨΊʹ͸αʔόʔɾ ϓϩϏδϣχϯάࣗಈԽ࡞ۀ͕ඞཁ w ߏஙखॱΛ*NNVUBCMFʹ͠ɺ3FQSPEVDJCMFͳαʔ όʔ؀ڥʹ͢Δ *EFNQPUFODFΛ୲อ͢Δ
  13. ߏ੒؅ཧπʔϧͷ ྺ࢙ͱ෼ྨ

  14. ߏ੒؅ཧπʔϧͷྺ࢙ $ IFG 1VQQFU "OTJCMF 5FSSBGPSN *UBN BF  

     
  15. ࣮૷ݴޠผ෼ྨ w 1VQQFU w $IFG w *UBNBF w 4FSWFSLJU 3VCZ

    w 5FSSBGPSN (P w "OTJCMF 1ZUIPO
  16. දݱผ෼ྨ w "OTJCMF w 4FSWFSLJU :".- w 5FSSBGPSN w 1VQQFU

    w $IFG w *UBNBF 3VCZ )$- %4-
  17. 8IZ:".- w 9.-+40/ΑΓهड़͕ϥΫ w ಛ௃ΑΈ΍͍͢ɺ͔͖΍͍͢ɺΘ͔Γ΍͍͢ w Ұൠతʹ࢖ΘΕ͍ͯΔهड़ϑΥʔϚοτֶशίε τ͕௿͍ʂ

  18. 8IZ)$-

  19. 8IZ)$- ❌+40/μϝίϝϯτ͔͚ͳ͍ɻ͠ΜͲ͍ɻ ❌:".-΋μ ϝॳ৺ऀʹ͸ه๏Ή͔͍ͣ͠ʂ ❌3VCZͱ͔΋μϝࣗ༝౓ߴ͗͌͢ʂෳࡶ͗͌͢ʂ ̋)$-ΑΖ͍͠ɺͳΒ͹ಠࣗݴޠͩɻ ཁ໿

  20. 8IZ3VCZ w %4-ͷॻ͖΍͢͞ w એݴతͳهड़ w ࣗ༝౓͕ߴ͍ package 'nginx' do

    action :install end service 'nginx' do action [:enable, :start] end
  21. *OGSBTUSVDUVSFBT$PEF ͷ֓೦੔ཧ

  22. *OGSBTUSVDUVSFBT$PEF 1SPWJTJPOJOH5PPMDIBJO1SFTFOUBUJPO<1%'>

  23. .BLFJU4JNQMF

  24. 4FSWFS$POpHVSBUJPO *OGSBTUSVDUVSFBT$PEF 4FSWFS4FUVQ "QQMJDBUJPO%FQMPZNFOU *OGSBTUSVDUVSFBT$PEF

  25. $POpHVSBUJPO *OGSBTUSVDUVSFBT$PEF 4FUVQ *OGSBTUSVDUVSFBT$PEF %FQMPZNFOU $IFG *UBNBF "OTJCMF 5FSSBGPSN 1SPWJTJPOFS

    1SPWJEFS $BQJTUSBOP "OTJTUSBOP
  26. ຊ౰ʹશͯ͸ίʔυԽ ͞Εͨͷ͔ʁ

  27. None
  28. None
  29. *OGSBTUSVDUVSFBT$PEF ͷΧόʔൣғ w *BB4͸Ծ૝αʔόҎ֎ʹ΋͞·͟·ͳαʔϏεΛఏ ڙ͍ͯ͠Δ w &-# 3%4 71$ 4

    $MPVE'SPOU *".  4FDVSJUZ(SPVQFUD w ͦΕΒʹର͢ΔΦϖϨʔγϣϯΛ"84 .BOBHFNFOU $POTPMFͳͲͷ(6*Ͱ΍Δ΂͖ͳͷ͔ʁ
  30. (6*$POpHVSBUJPOJTIBSEʜ w (6*ʹΑΔૢ࡞͸*NNVUBCMFͰ͸ͳ͍ w (6*͸มΘΔ͔΋͠Εͳ͍ w (6*ૢ࡞͸ϑΝδʔʢ໌֬ͳݴޠԽͰ͖ͳ͍ʣ w ॏཁͳઃఆΛ(6*೚ͤʹ͍͍ͯ͠ͷ͔ʁ w

    ➜ɹ͡Ό͋"1*Λୟ͚͹͍͍͡Όͳ͍ $POpHVSBUJPOBT$PEF
  31. $POpHVSBUJPO $POpHVSBUJPOBT$PEF 4FUVQ %FQMPZNFOU *OGSBTUSVDUVSFBT$PEF 4FSWFS$POpHVSBUJPO 4FSWJDF$POpHVSBUJPO &-# 3PVUF *".

    4FDVSJUZ(SPVQ 71$ 4 $MPVE'SPOU
  32. શ͕ͯίʔυʹͳΔ

  33. 3PVUF$POpHVSBUJPO hosted_zone "example.com." do rrset "example.com.", "A" do ttl 300

    resource_records( "127.0.0.1", "127.0.0.2" ) end end 1PXFSFECZ3PBEXPSLFS
  34. resource "aws_route53_record" "www" { zone_id = "${aws_route53_zone.primary.zone_id}" name = "www.example.com"

    type = "A" ttl = "300" records = ["${aws_eip.lb.public_ip}"] } 1PXFSFECZ5FSSBGPSN "841SPWJEFS 3PVUF$POpHVSBUJPO
  35. શ͕ͯίʔυʹͳΔ

  36. %BUBEPH"MFSU$POpHVSBUJPO monitor "Check load avg", :type=>"metric alert" do query "avg(last_5m):avg:ddstat.load_avg.1m{host:i-XXXXXXXX}

    > 1" message "@winebarrel@example.net" options do locked false new_host_delay 300 notify_no_data true no_data_timeframe 2 notify_audit true silenced({}) end end 1PXFSFECZ#FSLEPH
  37. (JUIVC.FNCFS.BOBHFNFOU resource "github_membership" "membership_for_some_user" { username = "SomeUser" role =

    "member" } resource "github_repository" "example" { name = "example" description = "My awesome codebase" private = true } resource "github_repository_collaborator" "a_repo_collaborator" { repository = "our-cool-repo" username = "SomeUser" permission = "admin" } 1PXFSFECZ5FSSBGPSNʢ(JUIVC1SPWJEFSʣ
  38. શ͕ͯϓϧϦΫͱͳΓ ϨϏϡʔՄೳʹͳΔ

  39. 4$POpHVSBUJPO 1PXFSFECZ5FSSBGPSN "841SPWJEFS

  40. *"..BOBHFNFOU 1PXFSFECZ.JBN

  41. શ͕ͯίʔυʹͳΔ w ϨϏϡʔʹΑΔνΣοΫମ੍ʹΑΓɺΑΓ҆શͳ $POpHVSBUJPOΦϖϨʔγϣϯΛ࣮ݱ w $*αʔϏεͱ࿈ܞͤͯ͞ςετɾ$%ͷࣗಈԽ΋Մ ೳͱͳΔ

  42. ·ͱΊ w ίʔυԽ͢Δ͜ͱʹΑΓ(JUIVCϫʔΫϑϩʔʢϓϧ ϦΫˠϨϏϡʔˠϚʔδʣʹ৐Δ͜ͱ͕Ͱ͖ͯϋο ϐʔ w *OGSBTUSVDUVSFBT$PEF4FSWFS$POpHVSBUJPOBT $PEF 4FSWJDF$POpHVSBUJPOBT$PEF

  43. ࢀߟࢿྉ w *UBNBF*OGSBBT$PEFݱঢ়֬ೝձ IUUQTTQFBLFSEFDLDPNSZPUBSBJ JUBNBFJOGSBBTDPEFYJBO[IVBOHRVFSFOIVJ  w 3FCVJME*NNVUBCMF*OGSBTUSVDUVSF IUUQSFCVJMEGN 

    w *OGSBTUSVDUVSFBT$PEF4QFBLFS%FDL IUUQTTQFBLFSEFDLDPNOBPZB JOGSBTUSVDUVSFBTDPEF  w *OGSBTUSVDUVSFBT$PEF࠶ߟ IUUQNJ[[ZPSHCMPH  w 5SBTI:PVS4FSWFSTBOE#VSO:PVS$PEF*NNVUBCMF*OGSBTUSVDUVSFBOE %JTQPTBCMF$PNQPOFOUT IUUQDIBEGPXMFSDPN JNNVUBCMFEFQMPZNFOUTIUNM  w *OGSBTUSVDUVSF"T$PEF IUUQNBSUJOGPXMFSDPNCMJLJ *OGSBTUSVDUVSF"T$PEFIUNM