![](/img/trans.png)
[英]How can I add/remove instances from GCE load balancers with Ansible?
[英]Ansible Rolling Deployment across Multiple Load Balancers
對於我們的生產環境,我們在每個區域都有負載均衡器,每個區域后面都有多個Web服務器。 我們希望在整個環境中使用Ansible進行滾動部署,但要求我們不要在每個區域中同時刪除太多服務器。 以下是我們庫存的示例:
[webservers]
server1.europe.ourdeployment.com
server2.europe.ourdeployment.com
server1.northamerica.ourdeployment.com
server2.northamerica.ourdeployment.com
server3.northamerica.ourdeployment.com
server4.northamerica.ourdeployment.com
server5.northamerica.ourdeployment.com
server6.northamerica.ourdeployment.com
server7.northamerica.ourdeployment.com
server8.northamerica.ourdeployment.com
我們的部署命令:
- hosts: webservers
serial: 3
tasks:
- include: tasks/deploy-application.yml
如果我們像這樣運行它,它會在第一批中取出歐洲的所有服務器,所以我們有停機時間。 我知道我們可以重新排序庫存文件以確保批次的運行,但這似乎很脆弱。 有一個更好的方法嗎?
即使它看起來像矯枉過正,最好的方法是將網絡服務器分組(重新排列庫存):
示例主機文件:
[webservers:children]
euwebservers
uswebservers
[euwebservers]
server1.europe.ourdeployment.com
server2.europe.ourdeployment.com
[uswebservers]
server1.northamerica.ourdeployment.com
server2.northamerica.ourdeployment.com
server3.northamerica.ourdeployment.com
server4.northamerica.ourdeployment.com
server5.northamerica.ourdeployment.com
server6.northamerica.ourdeployment.com
server7.northamerica.ourdeployment.com
server8.northamerica.ourdeployment.com
劇本:
# my_playbook.yml
---
- hosts: euwebservers
serial: 30%
tasks:
- include: tasks/deploy-application.yml
- hosts: uswebservers
serial: 30%
tasks:
- include: tasks/deploy-application.yml
- hosts: webservers
tasks:
- name: Do something on all webservers
template: src=foo dest=bar
您始終可以使用webservers
組或基於子組名稱的單個區域來尋址所有服務器。
另一種選擇是保留原始劇本,但限制執行特定服務器組:
# my_playbook.yml
---
- hosts: webservers
serial: 30%
tasks:
- include: tasks/deploy-application.yml
並運行ansible-playbook
如下:
ansible-playbook my_playbook.yml --limit=euwebservers
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.