Ansible 2.0 at Ansible Meetup in Tokyo 2015.09

28da29f13a2f4e6f602b7bfa032a94cc?s=47 shirou
September 14, 2015

Ansible 2.0 at Ansible Meetup in Tokyo 2015.09

28da29f13a2f4e6f602b7bfa032a94cc?s=128

shirou

September 14, 2015
Tweet

Transcript

  1. Ansible 2.0 @r_rudi एࢁ࢙࿠ (πΩϊϫגࣜձࣾ)

  2. ͓લͩΕΑ • एࢁ ࢙࿠@r_rudi / πΩϊϫגࣜձࣾ CTO • WebΞϓϦ։ൃ͔Βӡ༻·Ͱ •

    ීஈ͸golangͰWebΞϓϦॻ͍ͯ·͢ • ஶॻʮೖ໳Ansibleʯ • Amazonʹͯൢചத(ిࢠॻ੶)
  3. Ansible 2.0ͱ͸ • ࠷৽͸1.9.3 (1.9.4͕rc2) • 1ܥͱฏߦͯ͠2ܥ͕௕͍ؒ։ൃ͞Ε͍ͯͨ • গͳ͘ͱ΋ࠓ೥2݄Ҏ߱ •

    ಺෦ߏ଄Λ΄΅Ұ͔Βॻ͖௚ͨ͠ • ίʔυ໊: ”Over the Hills and Far Away” (Led Zeppelin)
  4. 2.0Ͱ࠷΋ॏཁͳ఺ • ࠓ೔͸͜Ε͚ͩΛ֮͑ͯؼͬͯԼ͍͞
 • ैདྷͷplaybookͱ100%ޓ׵ੑ͕͋Γ·͢ • طଘͷplaybookΛม͑Δඞཁ͸͋Γ·ͤΜ Λɺ໨ࢦ͍ͯ͠·͢

  5. ௥Ճػೳ

  6. block • taskΛ͞Βʹ෼ׂͰ͖·͢ tasks: - block: - yum: name={{ item

    }} state=installed with_items: - httpd - memcached - template: src=templates/src.j2 dest=/etc/foo.conf - service: name=bar state=started enabled=True when: ansible_distribution == 'CentOS'
  7. blockʹΑΔྫ֎ॲཧ tasks: - block: - debug: msg='࣮ߦ͞Ε·͢' - fail: msg=“fail!!!”

    - debug: msg=‘Τϥʔ͕ى͖ΔͨΊɺ͜͜͸࣮ߦ͞Ε·ͤΜ' rescue: - debug: msg=‘Τϥʔ͕͓͖·ͨ͠' - fail: msg=“rescue಺Ͱfail!!” - debug: msg='͜͜΋࣮ߦ͞Ε·ͤΜ' always: - debug: msg="ඞ࣮ͣߦ͞Ε·͢"
  8. block಺Ͱઃఆͷ্ॻ͖ - hosts:
 remote_user: someuser
 tasks: - block: - shell:

    whoami
 - shell: touch /etc/hosts
 become_user: root
  9. strategy plugin • λεΫ࣮ߦઓུΛมߋ͢Δ • linear: શϗετͷ࣮ߦऴྃΛ଴ͭ(v1ͱಉ͡) • free: ଴ͨͣʹͲΜͲΜ࣮ߦ͍ͯ͘͠

    • pluginͳͷͰɺ௥Ճ΋Մೳ
  10. includeͰwith͕࢖͑ΔΑ͏ʹ • include͸ม਺Λ্ॻ͖Ͱ͖͕ͨɺwithʹΑΔ ܁Γฦ͠͸Ͱ͖ͳ͔ͬͨɻ tasks: - include: foo.yml some_var={{ item

    }}
 with_items: [‘a’, ‘b’, ‘c’]
  11. include಺Ͱม਺Λ࢖͏ • ैདྷ͸ม਺ల։͕ग़དྷͳ͔ͬͨ • distributionຖʹwhenΛॻ͘ΑΓߦ਺અ໿ - include: included_{{ inventory_hostname }}.yml

  12. meta: refresh_inventory • inventoryϑΝΠϧ͸࠷ॳͷҰճ͔͠ಡΈࠐ· ͳ͔ͬͨ • dynamic inventoryͳͲͰ໰୊ʹ tasks: 


    - meta: refresh_inventory
  13. taskϨϕϧͰͷม਺ • taskϨϕϧͰఆٛɾ্ॻ͖͕Մೳʹ vars: aa: "AA" tasks: - debug: msg="{{

    aa }}" - debug: msg="{{ aa }}" vars: aa: “BB" - debug: msg="{{ aa }}” -> AA -> BB -> AA
  14. Ϟδϡʔϧ/pluginͷ௥Ճ • 140Ҏ্ͷ৽نϞδϡʔϧͷ௥Ճ • openstackɺdockerɺzabbixɺvmware… • inventory, connection plugin΋௥Ճ •

    serf, consul, dockerͳͲ • callback plugin͕ಉࠝɻansible.cfgʹॻ͚ͩ͘Ͱ༗ޮ Խ(callback_whitelist)
  15. ྫ: profile_tasks plugin [defaults] callback_whitelist = profile_tasks TASK [debug msg={{

    aa }}] ****************************************************** Monday 14 September 2015 16:00:20 +0900 (0:00:00.074) 0:00:00.162 ****** ok: [localhost] => { "changed": false, "msg": "AA" } Monday 14 September 2015 16:00:20 +0900 (0:00:00.078) 0:00:00.241 ****** =============================================================================== TASK: debug msg={{ aa }} ------------------------------------------------ 0.08s TASK: debug msg={{ aa }} ------------------------------------------------ 0.08s TASK: debug msg={{ aa }} ------------------------------------------------ 0.07s
  16. มߋ෦෼

  17. ಺෦ߏ଄ͷ੔ཧ • ม਺؅ཧ (VariableManager) • ैདྷม਺ͷ؅ཧʹ໰୊͕ଟ͔ͬͨ • ม਺ల։ͷॱং͕෼͔ΓͮΒ͔ͬͨ • pluginߏ଄ͷ੔ཧ

    • ܧঝߏ଄ͷ੔ཧ
  18. ಺෦APIͷมߋ • ࣗ࡞pluginʹଟগͷมߋ͕ඞཁ • lookup͸LookupBase classΛܧঝ͢ΔΑ͏ʹ • callback͸ ‘v2_’ Λ෇͚Δ

    • connection͸΄ͱΜͲͷਓ͕࡞͍ͬͯͳ͍͸ͣ • filter͸มߋͳ͠
  19. ࣗ࡞Ϟδϡʔϧ • Ҿ਺ͷ౉͠ํ͕มΘͬͨͷͰɺมߋ͕ඞཁʹ ͳΓ·͢ • http://qiita.com/h-hirokawa/items/ 8eecd64d01ad80175179

  20. ࡉ͔ͳมߋ఺ • templateͰbool΍਺஋Λจࣈܕʹม׵͍͕ͯͨ͠ɺม ߋ͠ͳ͍Α͏ʹ • ۭͷม਺ͱNoneΛۭനʹม׵͍͕ͯͨ͠ɺมߋ͠ͳ͍ Α͏ʹ • jinja2ͰͷΤεέʔϓͰ \\

    ͱ͍ͯͨ͠ͷΛ \ ʹ • YAMLϑΝΠϧதͰ > Λ࢖͍ͬͯͨ৔߹ʹ࠷ޙͷվߦ Λͦͷ··࢒͢Α͏ʹ
  21. python 3ରԠ • ࢒೦ͳ͕ΒೖΓ·ͤΜͰͨ͠ • ͨͩ͠ɺ४උ͸ਐΊ͍ͯΔ༷ࢠ • python 3ରԠPRΛड͚ೖΕ͍ͯΔ

  22. ·ͱΊ • Ansible 2.0ɻ·ͩग़ͯ·ͤΜɻɻɻ • playbookͷޓ׵ੑ 100% • 140Ҏ্ͷϞδϡʔϧͷ௥Ճ •

    blockʹΑΔྫ֎ॲཧͷ௥Ճ • ࣗ࡞ͷpluginʹ͸मਖ਼͕ඞཁ
  23. એ఻: PythonΤϯδχΞཆ੒ಡຊ • Ansibleͷ࿩Λॻ͍ͯ·͢ • 9݄17೔ʹansibleষͷಡॻձΛ΍Γ·͢ • http://pymook.connpass.com/ • ͋Β͔͡ΊಡΜͰ͖ͯؾʹͳͬͨ఺ɺΘ͔Βͳ͔ͬ

    ͨͱ͜ΖΛஶऀʹฉ͘ձͰ͢