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

夏休みで差がつく!Ansible/ansiblejp-20180803

 夏休みで差がつく!Ansible/ansiblejp-20180803

Ansible Night in Fukuoka 2018.08 の資料です。 #ansiblejp
https://ansible-users.connpass.com/event/93620/

356dbe9f00ed6a1f5dafe126029497f1?s=128

Kunihiro Morita

August 03, 2018
Tweet

Transcript

  1. ՆٳΈͰ͕ࠩͭ͘ʂ Ansible #ansiblejp 2018/8/3 Ansible Night in Fukuoka 2018.08 1

  2. ৿ా๜༟ גࣜձࣾΦϧλʔϒʔε ιϦϡʔγϣϯΞʔΩςΫτ ૊ΈࠐΈ → Ϋϥ΢υΠϯϑϥ @morita92hiro https://hawaku.hateblo.jp 2018/8/3 Ansible

    Night in Fukuoka 2018.08 2
  3. Ansibleపఈೖ໳ ൃചதʂ 2018/8/3 Ansible Night in Fukuoka 2018.08 3

  4. ͭ·Βͳ͍ੈք͔Β΋ͬͱܹࢗͷ͋Δੈք΁มԽͤ͞Α͏ʂ ɹɹɹɹɹ 2018/8/3 Ansible Night in Fukuoka 2018.08 4

  5. 2018/8/3 Ansible Night in Fukuoka 2018.08 5

  6. Ansibleͱ͸1 1 https://www.ansible.com/overview/it-automation 2018/8/3 Ansible Night in Fukuoka 2018.08 6

  7. ΤʔδΣϯτϨεʹίʔ υͰߏ੒؅ཧ͢Δπʔϧ 2018/8/3 Ansible Night in Fukuoka 2018.08 7

  8. ͳͥAnsibleΛ࢖͍࢝Ί͔ͨʁ! 2018/8/3 Ansible Night in Fukuoka 2018.08 8

  9. ࡞੒ͷґཔΛड͚Δ 2018/8/3 Ansible Night in Fukuoka 2018.08 9

  10. ୔ࢁͷ࡞੒ͷґཔΛड͚Δ 2018/8/3 Ansible Night in Fukuoka 2018.08 10

  11. • Ҋ݅͝ͱͷαʔόʔ • ։ൃɺຊ൪༻ • ෳ਺୆ߏங • Ϋϥ΢υʹΑΔαʔόʔͷ࢖͍ࣺͯ • ӡ༻

    ͜Εશ෦1ਓͰɾɾɾʁ 2018/8/3 Ansible Night in Fukuoka 2018.08 11
  12. Ͳ͏΍ͬͯࡹ͘ʁ 2018/8/3 Ansible Night in Fukuoka 2018.08 12

  13. !஥ؒΛݺͿ ͔͠͠ɺॿ͚͸ɾɾɾ! 2018/8/3 Ansible Night in Fukuoka 2018.08 13

  14. ௕͕࣌ؒΜ͹Δ 2018/8/3 Ansible Night in Fukuoka 2018.08 14

  15. #͍͍͑ 2018/8/3 Ansible Night in Fukuoka 2018.08 15

  16. Infrastructure as Code 2018/8/3 Ansible Night in Fukuoka 2018.08 16

  17. ʊਓਓਓਓਓਓਓʊ ʼɹಇ͖ํվֵɹʻ ʉY^Y^Y^Y^Y^Yʉ 2018/8/3 Ansible Night in Fukuoka 2018.08 17

  18. ߏ੒؅ཧπʔϧͳ͠ • खॱॻΛݩʹखಈͰઃఆ • खಈ͸ΦϖϛεͷՄೳੑ • खॱॻ͸ຊ౰ʹ࠷৽ʁ • ࢼ͞ΕΔهԱྗ •

    ൿ఻ͷλϨ 2018/8/3 Ansible Night in Fukuoka 2018.08 18
  19. ߏ੒؅ཧπʔϧ͋Γ • खॱΛίʔυͰهड़ • ίʔυΛ࣮ߦͯࣗ͠ಈͰઃఆ • ୭Ͱ΋࣮ߦͰ͖Δ • ίʔυ͕࠷৽ͷঢ়ଶ •

    όʔδϣϯ؅ཧ(Git)ͯ͠ɺҎલͷঢ়ଶʹ໭͢ͷ΋؆୯ • Կ౓࣮ߦͯ͠΋ಉ͡ঢ়ଶʢႈ౳ੑʣ 2018/8/3 Ansible Night in Fukuoka 2018.08 19
  20. ͞Βʹ 2018/8/3 Ansible Night in Fukuoka 2018.08 20

  21. ίʔυڞ௨Խ (Ansible Role) • ͍ͭ΋Πϯετʔϧ(sysstat, git౳) • ֤छϛυϧ΢ΣΞ(Apache, MySQL౳) •

    Ϋϥ΢υʹԠͨ͡ઃఆ(ϝϞϦΩϟογϡ౳) ࢖͑͹࢖͏΄ͲRoleࢿ࢈͕૿͑Δ 2018/8/3 Ansible Night in Fukuoka 2018.08 21
  22. Let's Ansible 2018/8/3 Ansible Night in Fukuoka 2018.08 22

  23. ࠷௿ݶඞཁͳ෺ • Python • AnsibleίϚϯυ • inventory • module •

    playbook 2018/8/3 Ansible Night in Fukuoka 2018.08 23
  24. AnsibleίϚϯυ Πϯετʔϧ $ pip install ansible 2018/8/3 Ansible Night in

    Fukuoka 2018.08 24
  25. inventory ࡞ۀର৅ͱͳΔϗετΛهड़͢ΔϑΝΠϧ [web] 192.168.0.10 [db] 192.168.0.20 2018/8/3 Ansible Night in

    Fukuoka 2018.08 25
  26. module Πϯετʔϧ΍αʔϏεىಈͳͲίϚϯυͷ෦෼ • yum • service $ ansible -i hosts

    web -m ping 192.168.0.10 | success >> { "changed": false, "ping": "pong" } 2018/8/3 Ansible Night in Fukuoka 2018.08 26
  27. playbook ϞδϡʔϧΛ࣮૷࣮ͯ͠ߦ͢Δ෦෼ - hosts: web sudo: yes tasks: - name:

    be sure httpd is installed yum: name=httpd state=installed - name: be sure httpd is running and enabled service: name=httpd state=running enabled=yes 2018/8/3 Ansible Night in Fukuoka 2018.08 27
  28. playbook࣮ߦ $ ansible-playbook -i hosts simple.yml PLAY [web] ************************************************************ GATHERING

    FACTS *************************************************************** ok: [192.168.0.10] TASK: [be sure httpd is installed] ******************************************** changed: [192.168.0.10] TASK: [be sure httpd is running and enabled] ********************************** changed: [192.168.0.10] PLAY RECAP ******************************************************************** 192.168.0.10 : ok=3 changed=2 unreachable=0 failed=0 2018/8/3 Ansible Night in Fukuoka 2018.08 28
  29. ଞʹ΋ • Ϋϥ΢υ • Vagrant • Windows • git •

    ωοτϫʔΫػث ͳͲͳͲ 2018/8/3 Ansible Night in Fukuoka 2018.08 29
  30. AnsibleΛಋೖ͍ͯ͠ΔՕॴ • αʔόʔϓϩϏδϣχϯά • ΞϓϦέʔγϣϯσϓϩΠ Ϋϥ΢υ෦෼͸AWS CloudFormation΍Azure ARM Templateɺ TerraformΛ࢖͍ͬͯ·͢ɻ

    2018/8/3 Ansible Night in Fukuoka 2018.08 30
  31. Ansibleͷӡ༻ 2018/8/3 Ansible Night in Fukuoka 2018.08 31

  32. ಈ࡞؀ڥ 2018/8/3 Ansible Night in Fukuoka 2018.08 32

  33. Πϯετʔϧ͸؆୯ • yum install ansible • apt-get install ansible •

    pip install ansible ͓޷Έͷํ๏Ͱ 2018/8/3 Ansible Night in Fukuoka 2018.08 33
  34. όʔδϣϯͷ૊Έ߹Θͤ • Python 2 (versions 2.6 or 2.7) • Python

    3 (versions 3.5 and higher) • Ansible 1.x or 2.x • Playbook࡞੒࣌ͷAnsibleόʔδϣϯ 2018/8/3 Ansible Night in Fukuoka 2018.08 34
  35. Ansibleઐ༻ಈ࡞؀ڥ͕͋Δ • ܧଓతʹϓϩϏδϣϯΠϯά͢ΔͨΊͷ؀ڥ͕͋Δ • όʔδϣϯ͸ݻఆ or ߹ΘͤΒΕΔ • Not ࠷৽͔΋͠Εͳ͍͕ಈ͘ʹࠔΒͳ͍

    !όʔδϣϯ໰୊͸ճආͰ͖ͦ͏ 2018/8/3 Ansible Night in Fukuoka 2018.08 35
  36. Ansibleಈ࡞؀ڥ͕ͳ͍ • ଞਓʹ࣮ߦͯ͠΋Β͍͍͚ͨͲಈ࡞؀ڥ͸ʁ • ୯ൃͷҊ݅ • ίϚϯυΞοϓσʔτޙͷPlaybookಈ͘ʁʢޙํޓ׵ʣ 2018/8/3 Ansible Night

    in Fukuoka 2018.08 36
  37. ͍ͨ͜͠ͱ • ؀ڥґଘ͔Βͷղ์ • ϙʔλϏϦςΟ 2018/8/3 Ansible Night in Fukuoka

    2018.08 37
  38. ίϯςφͰղܾͰ͖ͦ͏ 2018/8/3 Ansible Night in Fukuoka 2018.08 38

  39. Docker • Dockerfile FROM python:3.6-onbuild CMD [ "ansible", "--version" ]

    • requirements.txt ansible>=2.5.0,<2.6.0 • Docker Build docker build -t local/ansible:2.5 . 2018/8/3 Ansible Night in Fukuoka 2018.08 39
  40. docker run $ docker run -it --rm \ -v $HOME/.ssh:/root/.ssh:ro

    \ -v $PWD:/playbooks \ -w /playbooks \ hawaku/ansible:2.5 \ bash root@29867ac2540f:/playbooks# ansible -i hosts all -m ping 2018/8/3 Ansible Night in Fukuoka 2018.08 40
  41. alias alias ansible_2.5='docker run -it --rm \ -v $HOME/.ssh:/root/.ssh:ro \

    -v $PWD:/playbooks \ -w /playbooks \ hawaku/ansible:2.5 \ bash' $ ansible_2.5 root@29867ac2540f:/playbooks# ansible -i hosts all -m ping 2018/8/3 Ansible Night in Fukuoka 2018.08 41
  42. ΋͘͠͸ playbook ├── site.yml ├── Dockerfile ├── requirements.txt ├── inventories

    └── roles PlaybookʹDockerfileஔ͍ͱ͘ 2018/8/3 Ansible Night in Fukuoka 2018.08 42
  43. ·ͱΊ 2018/8/3 Ansible Night in Fukuoka 2018.08 43

  44. AnsibleಋೖͷޮՌ • Πϯϑϥͷߏஙʹ͸ֻ͕͔࣌ؒΔ • !ࣗಈԽͰߏங࣌ؒͷ୹ॖɾۭ͖࣌ؒ༗ޮ׆༻ • !ઃఆ࿙Εɾϛε͕ͳ͘඼࣭͕҆ఆ • ΠϯϑϥΤϯδχΞෆࡏͰͷΞϓϦέʔγϣϯσϓϩΠ 2018/8/3

    Ansible Night in Fukuoka 2018.08 44
  45. ఆ࣌ୀࣾ2 2 http://redhat.lookbookhq.com/jpansiblecomic 2018/8/3 Ansible Night in Fukuoka 2018.08 45

  46. ͓·͚ 2018/8/3 Ansible Night in Fukuoka 2018.08 46

  47. ࠇ͍ը໘޷͖Ͱ͢ΑͶʁ 2018/8/3 Ansible Night in Fukuoka 2018.08 47

  48. AWX 2018/8/3 Ansible Night in Fukuoka 2018.08 48

  49. AWXͰͰ͖Δ͜ͱ • AnsibleίϚϯυͷGUI൛ • Ϣʔβʔೝূ • ϩʔϧ؅ཧ • ࣮ߦཤྺ •

    Rest API ͳͲͳͲ 2018/8/3 Ansible Night in Fukuoka 2018.08 49
  50. Azure Cloud Shell ϒϥ΢βͰαʔόʔϨεͰAnsibleಈ͖·͢ 2018/8/3 Ansible Night in Fukuoka 2018.08

    50
  51. Azure × Ansible 2018/8/3 Ansible Night in Fukuoka 2018.08 51

  52. ͓ΘΓ 2018/8/3 Ansible Night in Fukuoka 2018.08 52