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

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

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/

toshimaru

November 02, 2016
Tweet

More Decks by toshimaru

Other Decks in Technology

Transcript

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  5. ൿ఻ͷλϨ

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  9. *NNVUBCMF
    *OGSBTUSVDUVSF

    View full-size slide

  10. r$IBE'PXMFS

    l5SBTI:PVS4FSWFSTBOE#VSO:PVS$PEF*NNVUBCMF
    *OGSBTUSVDUVSFBOE%JTQPTBCMF$PNQPOFOUTz

    View full-size slide

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

    View full-size slide

  12. *NNVUBCMF*OGSBTUSVDUVSF
    w "84 ($1Λ࢝Ίͱ͢Δ*BB4ొ৔ʹΑΓμΠφϛοΫͳ
    αʔόʔߏ੒͕Մೳͱͳͬͨ
    w Ϙλϯ̍ͭͰ্͛Լ͛͢Δαʔόʔ %JTQPTBCMFͳ
    αʔόʔ
    ஀ੜ
    w ΦʔτεέʔϦϯάͷԸܙΛڗड͢ΔͨΊʹ͸αʔόʔɾ
    ϓϩϏδϣχϯάࣗಈԽ࡞ۀ͕ඞཁ
    w ߏஙखॱΛ*NNVUBCMFʹ͠ɺ3FQSPEVDJCMFͳαʔ
    όʔ؀ڥʹ͢Δ *EFNQPUFODFΛ୲อ͢Δ

    View full-size slide

  13. ߏ੒؅ཧπʔϧͷ
    ྺ࢙ͱ෼ྨ

    View full-size slide

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

    View full-size slide

  15. ࣮૷ݴޠผ෼ྨ
    w 1VQQFU
    w $IFG
    w *UBNBF
    w 4FSWFSLJU
    3VCZ
    w 5FSSBGPSN
    (P
    w "OTJCMF
    1ZUIPO

    View full-size slide

  16. දݱผ෼ྨ
    w "OTJCMF
    w 4FSWFSLJU
    :".-
    w 5FSSBGPSN
    w 1VQQFU
    w $IFG
    w *UBNBF
    3VCZ
    )$-
    %4-

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  19. 8IZ3VCZ
    w %4-ͷॻ͖΍͢͞
    w એݴతͳهड़
    w ࣗ༝౓͕ߴ͍
    package 'nginx' do
    action :install
    end
    service 'nginx' do
    action [:enable, :start]
    end

    View full-size slide

  20. *OGSBTUSVDUVSFBT$PEF
    ͷ֓೦੔ཧ

    View full-size slide

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

    View full-size slide

  22. .BLFJU4JNQMF

    View full-size slide

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

    View full-size slide

  24. $POpHVSBUJPO
    *OGSBTUSVDUVSFBT$PEF
    4FUVQ
    *OGSBTUSVDUVSFBT$PEF
    %FQMPZNFOU
    $IFG
    *UBNBF
    "OTJCMF
    5FSSBGPSN
    1SPWJTJPOFS
    1SPWJEFS
    $BQJTUSBOP
    "OTJTUSBOP

    View full-size slide

  25. ຊ౰ʹશͯ͸ίʔυԽ
    ͞Εͨͷ͔ʁ

    View full-size slide

  26. *OGSBTUSVDUVSFBT$PEF
    ͷΧόʔൣғ
    w *BB4͸Ծ૝αʔόҎ֎ʹ΋͞·͟·ͳαʔϏεΛఏ
    ڙ͍ͯ͠Δ
    w &-# 3%4 71$ 4 $MPVE'SPOU *".
    4FDVSJUZ(SPVQFUD
    w ͦΕΒʹର͢ΔΦϖϨʔγϣϯΛ"84 .BOBHFNFOU
    $POTPMFͳͲͷ(6*Ͱ΍Δ΂͖ͳͷ͔ʁ

    View full-size slide

  27. (6*$POpHVSBUJPOJTIBSEʜ
    w (6*ʹΑΔૢ࡞͸*NNVUBCMFͰ͸ͳ͍
    w (6*͸มΘΔ͔΋͠Εͳ͍
    w (6*ૢ࡞͸ϑΝδʔʢ໌֬ͳݴޠԽͰ͖ͳ͍ʣ
    w ॏཁͳઃఆΛ(6*೚ͤʹ͍͍ͯ͠ͷ͔ʁ
    w ➜ɹ͡Ό͋"1*Λୟ͚͹͍͍͡Όͳ͍
    $POpHVSBUJPOBT$PEF

    View full-size slide

  28. $POpHVSBUJPO
    $POpHVSBUJPOBT$PEF
    4FUVQ
    %FQMPZNFOU
    *OGSBTUSVDUVSFBT$PEF
    4FSWFS$POpHVSBUJPO 4FSWJDF$POpHVSBUJPO
    &-#
    3PVUF
    *".
    4FDVSJUZ(SPVQ
    71$
    4
    $MPVE'SPOU

    View full-size slide

  29. શ͕ͯίʔυʹͳΔ

    View full-size slide

  30. 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

    View full-size slide

  31. 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

    View full-size slide

  32. શ͕ͯίʔυʹͳΔ

    View full-size slide

  33. %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 "@[email protected]"
    options do
    locked false
    new_host_delay 300
    notify_no_data true
    no_data_timeframe 2
    notify_audit true
    silenced({})
    end
    end
    1PXFSFECZ#FSLEPH

    View full-size slide

  34. (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ʣ

    View full-size slide

  35. શ͕ͯϓϧϦΫͱͳΓ
    ϨϏϡʔՄೳʹͳΔ

    View full-size slide

  36. 4$POpHVSBUJPO
    1PXFSFECZ5FSSBGPSN "841SPWJEFS

    View full-size slide

  37. *"..BOBHFNFOU
    1PXFSFECZ.JBN

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  40. ࢀߟࢿྉ
    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

    View full-size slide