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

With Ansible and Terraform

san-tak
July 30, 2019

With Ansible and Terraform

Ansible ユーザー会
2019/7/30 Ansible Night in Tokyo 2019.07 LT 説明資料
https://ansible-users.connpass.com/event/135965/

san-tak

July 30, 2019
Tweet

More Decks by san-tak

Other Decks in Technology

Transcript

  1. 5FSSBGPSNͬͯ ਓؾ্ঢதʁ !4 Ansible Chef Terraform Google Trend https://azure.microsoft.com/ja-jp/solutions/devops/terraform/ https://jp.alibabacloud.com/solutions/devops/terraform

    5FSSBGPSNιϦϡʔγϣϯ IUUQTHJUIVCDPN(PPHMF$MPVE1MBUGPSNUFSSBGPSNFS طଘͷ؀ڥ͔Β5FSSBGPSN༻ͷఆٛϑΝΠϧ Λੜ੒͢Δπʔϧʢ($1͕։ൃʣ https://blog.pulumi.com/using-terraform-remote-state-with-pulumi 1VMVNJͰ5FSSBGPSNTUBUFϑΝΠϧ ΛಡΈࠐΈͰ͖ΔΑ
  2. *B$πʔϧͷҐஔ෇͚੔ཧ !5 ωοτϫʔΫج൫ Ծ૝Խج൫ ίϯςφج൫ ΦϯϓϨϛε ύϒϦοΫΫϥ΢υ "[VSF ($1 "84

    LT 0QFO4UBDL 7.8BSF 0QFO4IJGU /495 Heat μΠφϛοΫΠϯϑϥετϥΫνϟϓϥοτϑΥʔϜ ΠϯϑϥετϥΫνϟఆٛπʔϧ CloudFormation Terraform αʔόʔߏ੒πʔϧ Ansible ੔ཧ࣠ͷҾ༻ݩ "[VSF4UBDL (,&0OQSFN "840VUQPTUT Πϯϑϥج൫ӡ༻ऀ ۀ຿޲͚ Πϯϑϥ؅ཧऀ ۀ຿։ൃऀ AP Πϯϑϥج൫ఏڙଆ Πϯϑϥج൫ར༻ଆ ʮҐஔ෇͚ʯͷ੔ཧͰ͋ΓػೳతͳΦʔό ϥοϓ͸͋Δɺͱهࡌ͞Ε͍ͯ·͢ɻ
  3. 5FSSBGPSNͱ"OTJCMFΛ Ұॹʹ࢖͏ʁ !6 https://www.redhat.com/ja/resources/hashicorp-terraform-ansible-infrastructure-as-code-overview TERRAFORM INVOKING ANSIBLE AUTOMATION ANSIBLE AUTOMATION

    INVOKING TERRAFORM ͜ͷࢿྉʹ͸ҎԼͷ̎ྫ͕Ͱ͖Δͱهࡌ͞Ε͍ͯΔ HCL (HashiCorp Configuration Language) Playbook Playbook Ansible Module HCL ʢݸਓͷײ૝Ͱ͢ʣ πʔϧΛࠞͥͯ࢖Θͳ͍ํ͕ྑ͍ͷͰ͸ʁ ࠨهͷ̎ྫͷར఺͕Θ͔Βͳ͍ɻɻ τϥϒϧγϡʔςΟϯά͕େมͦ͏ɻ ʮͰ͖Δʯͱॻ͍ͯ͋Δ͕ɻɻɻ ͜ͷΑ͏ʹ૊Έ߹ΘͤΔཧ༝΍ Ձ஋ʹ͍ͭͯઆ໌͕ͳ͘ࠔ࿭ ʢ͜ͷࢿྉ͕ࠓճͷ-5ͷ ΩοΧέʹʣ
  4. !7 ͪΐͬͱ͚ͩৄ͘͠ݟͯΈΔͱɻɻ ϝϯςφϯε؍఺͔Β TERRAFORM INVOKING ANSIBLE AUTOMATION ANSIBLE AUTOMATION INVOKING

    TERRAFORM hcl resource “aws_instance” “web” { # ... provisioner “local-exec” { command = “ansible-playbook -u ubuntu -i ‘${aws_instance.web.public_dns},’ main.yml” } } --- - name: main hosts: all gather_facts: false connection: local tasks: - name: plan terraform: project_path: ‘terraform/’ plan_file: “{{playbook_dir}}/tfplan” lock: true state: planned 5FSSBGPSNͰ&$Λ࡞੒͠ɺ࡞੒͕׬ྃͨ͠ޙ 1MBZCPPLͰઃఆ͍ͯ͠Δ ʢޙॲཧͷΠϝʔδʣ 1MBZCPPLͷ࣮ߦ͕ࣦഊ͢Δͱɺ5FSSBGPSN্ͷঢ়ଶ͸z5BJOUFEzͱͳΔɻ ໰୊Λղܾ͠࠶౓BQQMZΛ࣮ߦ͢Δͱɺ&$͸Ұ୴࡟আ͞Εͯ࠶࡞੒͞Εͨޙɺ1MBZCPPL͕࣮ߦ͞ΕΔɻ 1MBZCPPLΛ࣮ߦ͢Δͱɺ5FSSBGPSNϞδϡʔϧ͔Βొ࿥ ͞Ε͍ͯΔ)$-Λݺͼग़͢ ʢϝΠϯॲཧͷҰ෦ʣ 5FSSBGPSN͕࡞੒ͨ͠Ϧιʔε ྫ͑͹αʔό ͷΠϯϕϯτϦ৘ใΛ͜ͷޙͷUBTL ΍3PMFͳͲʹ౉͢ඞཁ͕͋Δɻ μΠφϛοΫΠϯϕϯτϦΛ࢖ͬͯରॲ͢Δϊ΢ϋ΢͕ωοτ্Ͱݟ͚ͭΒΕ·͢ɻ ແ͠ɺ͔ͳ ͋ͬͯ΋͍
  5. 5PXFS͔Β࢖͏ !8 No. Ansible Terraform ༗ ແ ༗Γɾແ͠ͷཧ༝ 1 Tower

    Enterprise º ྆ํͱ΋ߴػೳͳ(6*͕͋Γɺશମ੍ޚʹ ͲͪΒΛ࢖͏΂͖͔෼͔Βͳ͘ͳΔ ੍ޚର৅Ͱ࢖͍෼͚ΔͷͰ͋Ε͹༗Γ 2 Tower OSS ˓ *B$੔ཧͷΑ͏ʹΠϯϑϥΛ5FSSBGPSNͰɺ ίϯϑΟάΛ"OTJCMFͰߦ͍ɺશମ੍ޚΛ 5PXFSͷϫʔΫϑϩʔͰ࣮ݱ 3 Engine Enterprise ˚ શମ੍ޚ͸5FSSBGPSN͔Β࣮ࢪɻ"OTJCMF 1MBZCPPL͕͢Ͱʹ੔උࡁΈͷ৔߹΍ 5FSSBGPSNͰ͸ίϯϑΟάͰ͖ͳ͍ࣄ߲ʹ "OTJCMFΛར༻͢Δύλʔϯ 4 Engine OSS ˚ ͦΕͧΕͰׯবͤͣʹ੍ޚର৅Ͱ࢖͍෼͚ ΔͷͰ͋Ε͹༗Γ +FOLJOTͳͲ্͕Ґʹ͍ͯɺͦΕͧΕΛผ λεΫͰ੍ޚ͢ΔͱదࡐదॴͰ࢖͑ͦ͏ ੍ޚର৅ͱͳΔγεςϜΛ྆ํͷπʔϧͰ૊Έ߹Θ੍ͤͯޚ͢Δ͔Ͳ͏͔ͱݴ͏؍఺Ͱ͢ 5PXFSͰ֎෦γεςϜ͔Βͷೝূ৘ใ࿈ܞͱͯ͠ɺ)BTIJ$PSQ7BVMU͕બ୒Ͱ͖ΔΑ͏ʹ ͳΓ·ͨ͠ɻ)BTIJ$PSQϓϩμΫτΛ׆༻͍ͯ͠Δ৔߹ͷ࿈ܞ͕ਐΉՄೳੑ͕͋Γ·͢ɻ ҎԼͷ૊Έ߹ΘͤͰͷߟ࡯
  6. !9 AWS "OTJCMF5PXFSͷϫʔΫϑϩʔ͔Β࣮ߦ͢Δ 1MBZCPPLδϣϒ 8FCαʔόઃఆ ύοέʔδΞοϓσʔτɺ Πϯετʔϧɺίϯςϯπద༻ 1MBZCPPLδϣϒ σʔλઃఆ ^

    ྫ͑͹ɺڭҭ؀ڥͳͲେྔʹ ·ͱΊͯߏங͢Δ৔߹ͳͲ 0OF1VTIͰ ΠϯϑϥΛߏங 71$ &-# &$ 3%4 4 8FCαʔόઃఆ ύοέʔδΞοϓσʔτɺ Πϯετʔϧɺίϯςϯπద༻ σʔλઃఆ δϣϒςϯϓϨʔτผʹ࣮ߦ͢Δํ͕γϯϓϧ͔ "84͚ͩͩͬͨΒ$'O͕͍͍ͱࢥ͏͕ɺ"[VSF ͱ͔($1΋࢖͏৔߹͸ɺ5FSSBGPSNͰ౷ҰײΛ લϖʔδ/PͷΠϝʔδ ΠϯϑϥΛߏங 71$ &-# &$ 3%4 4 5FSSBGPSN࣮ߦ༻δϣϒ 1MBZCPPL 5FSSBGPSNϞδϡʔϧ࢖༻
  7. !13 ओཁػೳ "OTJCMF5PXFS 5FSSBGPSN&OUFSQSJTF 8FCϕʔε6* ˓ ˓ ݖݶ؅ཧ ˓ ˓

    δϣϒϫʔΫϑϩʔ ˓ º ΠϯϕϯτϦ؅ཧ ˓ ˓ 7$4࿈ܞ ˓ ˓ "OTJCMF&OHJOFʹ͸ແ͘5PXFSͷΈͰ࣮૷͞Ε͍ͯΔ΋ͷ 044൛5FSSBGPSNʹ͸ແ͘&OUFSQSJTF൛ͷΈͰ࣮૷͞Ε͍ͯΔ΋ͷ ิ଍ࢿྉ