利利⽤用⾃自動化的
建置、測試與部署
,完美創造出可信賴
的軟體發佈
- Jez Humble & David Farley
《Continuous Delivery 中⽂文版》- https://goo.gl/SK745B
20
Slide 21
Slide 21 text
建置
測試
發佈
部署
⾃自動化
21
Slide 22
Slide 22 text
建置
測試
發佈
部署
⾃自動化
22
Slide 23
Slide 23 text
建置
測試
發佈
部署
⾃自動化
23
Slide 24
Slide 24 text
建置
測試
發佈
部署
⾃自動化
24
Slide 25
Slide 25 text
建置
測試
發佈
部署
⾃自動化
25
Slide 26
Slide 26 text
建置
測試
發佈
部署
⾃自動化
26
Slide 27
Slide 27 text
持續交付和持續部署有什什麼不同?
Continuous Delivery
Continuous Deployment
auto auto manual
Build Deploy Test Release
auto auto auto
Build Deploy Test Release
27
Slide 28
Slide 28 text
持續交付和持續部署有什什麼不同?
前者需⼿手動 Release ⾄至 Production,⽽而後者則⾃自動化之。
Continuous Delivery
Continuous Deployment
auto auto manual
Build Deploy Test Release
auto auto auto
Build Deploy Test Release
28
70
lineinfile
• ⽤用正規表⽰示式對檔案進⾏行行插入或取代⽂文字的檔案模組 (Files Modules)。
• 其類似的 Linux 指令為 sed。
# Before 2.3, option 'dest', 'destfile' or 'name' was used instead of ‘path'.
# 關閉 SELinux。
- name: disable selinux
lineinfile:
path: /etc/selinux/config
regexp: '^SELINUX='
line: 'SELINUX=enforcing'
# 移除 docker 使⽤用者的 sudo 權限。
- name: remove sudo permission of docker
lineinfile:
path: /etc/sudoers
state: absent
regexp: '^docker'
Slide 71
Slide 71 text
71
shell
• 在遠端⽤用 /bin/sh 執⾏行行 shell 指令的指令模組 (Commands Modules),
⽀支援變數 (variables)、< , > , | , ; 和 & 等運算。
# 藉由 ls 和 wc 檢查檔案數量量。
- name: check files number
shell: ls /home/docker/ | wc -l
# 列列出所有的 Python ⾏行行程。
- name: show all python process
shell: ps aux | grep python
# 執⾏行行 shell script,並把結果導向 /tmp/result.log。
- name: execute run.sh
shell: ./run.sh > /tmp/result.log
Slide 72
Slide 72 text
72
Play Playbooks
Slide 73
Slide 73 text
Playbooks Samples
• Ansible Role: Install Vim and use vi-mode in everyway
- https://github.com/chusiang/vim-and-vi-mode.ansible.role
• Ansible Role: PHP 7 (php-fpm) for Nginx on Ubuntu and CentOS
- https://github.com/chusiang/php7.ansible.role
• Ansible Galaxy
- https://galaxy.ansible.com/
• Code samples from 《Ansible: Up and Running》
- https://github.com/ansiblebook/ansiblebook
73