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/

Kunihiro Morita

August 03, 2018
Tweet

More Decks by Kunihiro Morita

Other Decks in Technology

Transcript

  1. ߏ੒؅ཧπʔϧ͋Γ • खॱΛίʔυͰهड़ • ίʔυΛ࣮ߦͯࣗ͠ಈͰઃఆ • ୭Ͱ΋࣮ߦͰ͖Δ • ίʔυ͕࠷৽ͷঢ়ଶ •

    όʔδϣϯ؅ཧ(Git)ͯ͠ɺҎલͷঢ়ଶʹ໭͢ͷ΋؆୯ • Կ౓࣮ߦͯ͠΋ಉ͡ঢ়ଶʢႈ౳ੑʣ 2018/8/3 Ansible Night in Fukuoka 2018.08 19
  2. ίʔυڞ௨Խ (Ansible Role) • ͍ͭ΋Πϯετʔϧ(sysstat, git౳) • ֤छϛυϧ΢ΣΞ(Apache, MySQL౳) •

    Ϋϥ΢υʹԠͨ͡ઃఆ(ϝϞϦΩϟογϡ౳) ࢖͑͹࢖͏΄ͲRoleࢿ࢈͕૿͑Δ 2018/8/3 Ansible Night in Fukuoka 2018.08 21
  3. ࠷௿ݶඞཁͳ෺ • Python • AnsibleίϚϯυ • inventory • module •

    playbook 2018/8/3 Ansible Night in Fukuoka 2018.08 23
  4. 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
  5. 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
  6. 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
  7. ଞʹ΋ • Ϋϥ΢υ • Vagrant • Windows • git •

    ωοτϫʔΫػث ͳͲͳͲ 2018/8/3 Ansible Night in Fukuoka 2018.08 29
  8. Πϯετʔϧ͸؆୯ • yum install ansible • apt-get install ansible •

    pip install ansible ͓޷Έͷํ๏Ͱ 2018/8/3 Ansible Night in Fukuoka 2018.08 33
  9. όʔδϣϯͷ૊Έ߹Θͤ • 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
  10. 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
  11. 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
  12. 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
  13. ΋͘͠͸ playbook ├── site.yml ├── Dockerfile ├── requirements.txt ├── inventories

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