跨多个负载均衡器的可靠滚动部署

时间:2015-09-08 14:42:27

标签: ansible

对于我们的生产环境,我们在每个区域都有负载均衡器,每个区域后面都有多个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

如果我们像这样运行它,它会在第一批中取出欧洲的所有服务器,因此我们有停机时间。我知道我们可以重新排序库存文件以确保批次的运行,但这似乎很脆弱。有更好的方法吗?

1 个答案:

答案 0 :(得分:3)

即使它看起来有点矫枉过正,最好的方法是将网络服务器分组(重新排列库存):

示例主机文件:

[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