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

Ansible + GitLab で楽に何度もデプロイする話 #ゆるWeb札幌

Ansible + GitLab で楽に何度もデプロイする話 #ゆるWeb札幌

ゆるWeb勉強会@札幌 #8 (中止)
https://mild-web-sap.connpass.com/event/164107/

勉強会を中止にしたので、資料のみ。

Kihara, Takuya

February 15, 2020
Tweet

More Decks by Kihara, Takuya

Other Decks in Technology

Transcript

  1. !UBDDL ΏΔ8FCษڧձ!ࡳຈ ΏΔ8FCࡳຈ • ໊લ ໦ݪ ୎໵ / @tacck •

    ॴଐ גࣜձࣾϊʔεσΟςʔϧ
 ։ൃDivision ٕज़ਪਐGroup / Leader • ओ࠵ • ΏΔWebษڧձ@ࡳຈ • εϚʔτεϐʔΧʔͰ༡΅͏ձ@ࡳຈ • ޷͖ͳϑΟΪϡΞεέʔτͷٕ εϓϨουɾΠʔάϧ ୭ PHP Conference Hokkaido 2019
  2. !UBDDL ΏΔ8FCษڧձ!ࡳຈ ΏΔ8FCࡳຈ • ࣾ಺ͷҊ݅ͰɺαʔόʔҠ؅͕ඞཁͩͬͨɻ • ௒খن໛ͷอक • ͋Δاۀ಺޲͚εϚʔτϑΥϯΞϓϦͷ
 ഑෍༻αʔό

    (ΦϯϓϨ) • ࣾ಺ͷϚγϯ੔ཧʹ൐͍ɺAWS Lightsail ΁Ҡ؅ɻ • ϑΝΠϧͷ഑ஔɺ֬ೝ߲໨ͳͲ͸͢Ͱʹݻ·͍ͬͯΔͷͰɺ
 εϜʔζʹ࡞ۀ͢ΔͨΊɻ ͦ΋ͦ΋
  3. !UBDDL ΏΔ8FCษڧձ!ࡳຈ ΏΔ8FCࡳຈ • Ansible ʹΑΔΠϯϑϥͷίʔυԽ (IaaC) • GitLab CI/CD

    ʹΑΔσϓϩΠͷࣗಈԽ (DevOps) • ࠓޙΛݟਾ͑ͯ΍͓͖͔ͬͯͨͬͨɻ • ίʔυԽ͓ͯ͘͠ͱࣾ಺΁ͷ஌ݟల։΋͠΍͍͢ͷͰɺ
 ৭ʑͱ໾ʹཱͭɻ ͦͷͨΊ
  4. !UBDDL ΏΔ8FCษڧձ!ࡳຈ ΏΔ8FCࡳຈ • Python ੡ • ΤʔδΣϯτϨε • ૢ࡞ର৅ʹɺಛผͳԿ͔ΛೖΕͳͯ͘ྑ͍ɻ


    ( SSH ͱ Python ͕͋Ε͹ྑ͍ɻ) • YAML • ઃఆ͸YAMLͰهड़Մೳɻ • ઃఆͷه๏ͦͷ΋ͷͷशಘ೉қ౓͸௿͍ɻ
 (࢖͍͍ͨػೳ͝ͱʹ֮͑Δ͜ͱ͸ɺ΋ͪΖΜ͋Γ·͢ɻ) "OTJCMFͷಛ௃
  5. !UBDDL ΏΔ8FCษڧձ!ࡳຈ ΏΔ8FCࡳຈ • ႈ౳ੑ • ʮԿ౓࣮ߦͯ͠΋ಉ͡ঢ়ଶʹͳΔʯ͜ͱΛαϙʔτɻ • ͨͩ͠ɺϞδϡʔϧͷ࣮૷࣍ୈɻ •

    ϑΝΠϧ഑ஔ΍αʔϏεΠϯετʔϧͱ͍ͬͨ΋ͷ͸ɺ
 جຊతʹαϙʔτ͞Ε͍ͯΔɻ • ʮίϚϯυ࣮ߦʯܥͷϞδϡʔϧ͸ɺ
 αϙʔτ͞Ε͍ͯͳ͍Մೳੑ͕͋ΔͷͰ஫ҙɻ
 (Ansible ͔ΒݟͯอূͰ͖ͳ͍ͷͰɻ) "OTJCMFͷಛ௃
  6. !UBDDL ΏΔ8FCษڧձ!ࡳຈ ΏΔ8FCࡳຈ • 2012೥ʹ “Ansible, Inc.” ͕։ൃ։࢝ɻ • 2013೥ʹ

    ࢲ΋࢖͍࢝Ίͨ (Β͍͠) ɻ
 https://qiita.com/tacck/items/e3669b94e6a8066ce642 • ͜ͷ࣌ظ͸ߏ੒؅ཧπʔϧͷོ੝ظɻ • “Chef” ͕ڧ͔ͬͨهԱɻ (Ruby੡) • 2015೥ʹ Red Hat ࣾʹΑΓങऩɻ • ͪͳΈʹɺ Red Hat ࣾ΋ 2018೥ʹ IBM ࣾʹΑΓങऩɻ "OTJCMFͷྺ࢙
  7. !UBDDL ΏΔ8FCษڧձ!ࡳຈ ΏΔ8FCࡳຈ • ର৅ͱͳΔϗετͷ৘ใ (Inventory) • INIܗࣜ or YAMLܗࣜ

    (ൺֱత࠷ۙରԠ͞Εͨ) • աڈͷ৘ใΛάάΔͱɺINIܗࣜͷ৘ใ͕ͨ͘͞Μɻ • ૢ࡞಺༰ (Playbook) • ػೳ୯ҐͰ෼ׂ͢Δ Roles ܗࣜͰॻ͘ͷ͕Ұൠతɻ "OTJCMFઃఆͷجຊ
  8. !UBDDL ΏΔ8FCษڧձ!ࡳຈ ΏΔ8FCࡳຈ 1MBZCPPL NBJOZNM --- - hosts: all become:

    yes vars_files: - "vars/{{ stage }}.yml" roles: - setups - file_upload
  9. !UBDDL ΏΔ8FCษڧձ!ࡳຈ ΏΔ8FCࡳຈ 1MBZCPPL SPMFTTFUVQTUBTLTNBJOZNM --- - name: set timezon

    Asia/Tokyo shell: timedatectl set-timezone Asia/Tokyo - name: install httpd yum: name: httpd state: latest - name: enable httpd systemd: name: httpd enabled: yes - name: restart httpd systemd: name: httpd state: restarted
  10. !UBDDL ΏΔ8FCษڧձ!ࡳຈ ΏΔ8FCࡳຈ • GitHub Έ͍ͨͳ Git Repository αʔϏεɻ •

    ͦͷதͷػೳͱͯ͠ɺ “CI/CD” ͕͋Δɻ • ϦϙδτϦʹ͋ΔίʔυΛ࢖ͬͯɺ
 ৭ʑ΍͍͍ͬͯΑ! ͱ͍͏αʔϏεɻ (JU-BC
  11. !UBDDL ΏΔ8FCษڧձ!ࡳຈ ΏΔ8FCࡳຈ • ઃఆΛ YAML Ͱهड़ɻ • ίʔυͷνΣοΫɺϑϩϯτΤϯυͷϏϧυɺ
 αʔόʔ΁ͷσϓϩΠͳͲͳͲΛهड़Մೳɻ

    • ઃఆهड़ޙ͸ɺ git push ͢ΔͨͼʹࣗಈͰ࣮ߦ͞ΕΔɻ • खಈͰͷ࣮ߦɾ࠶࣮ߦ΋Մೳɻ (JU-BC$*$%
  12. !UBDDL ΏΔ8FCษڧձ!ࡳຈ ΏΔ8FCࡳຈ (JU-BC$*$% HJUMBCDJZNMൈਮ stages: - deploy - testing

    .deploy_job: &deploy_job stage: deploy image: cytopia/ansible:2.9-tools script: - ansible-playbook -i hosts/${APP_ENV}/inventory main.yml deploy testing: <<: *deploy_job variables: APP_ENV: testing before_script: - chmod 755 . - cat $SSH_KEY_PEM > hosts/testing/web_testing.pem - chmod 600 hosts/testing/web_testing.pem
  13. !UBDDL ΏΔ8FCษڧձ!ࡳຈ ΏΔ8FCࡳຈ • Ansible Λ࢖ͬͯΠϯϑϥ (αʔόͷߏ੒) ΛίʔυԽɻ • ίʔυʹͳ͍ͬͯΕ͹ɺσϓϩΠ΋ࣗಈԽՄೳɻ


    (GitLab CI/CD) • σϓϩΠ΋ࣗಈԽ͞Ε͍ͯΕ͹ɺ
 ͙͢ʹ҆ఆͨ͠؀ڥΛखʹೖΕΒΕΔ!! • ςετͩͬͯॻ͚ͪΌ͏!!! • ಈ͘΋ͷΛఏࣔͰ͖ΔͷͰɺਓʹ΋఻͑΍͍͢ɻ ·ͱΊ