跨多个负载平衡器的Ansible滚动部署

跨多个负载平衡器的Ansible滚动部署,ansible,Ansible,对于我们的生产环境,每个区域都有负载平衡器,每个区域后面都有多个Web服务器。我们希望在整个环境中使用Ansible进行滚动部署,但要求我们不要在每个区域一次关闭太多服务器。以下是我们的库存示例: [webservers] server1.europe.ourdeployment.com server2.europe.ourdeployment.com server1.northamerica.ourdeployment.com server2.northamerica.ourdeploymen

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

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

即使看起来有些过分,最好的方法还是将Web服务器分组(重新排列目录):

示例主机文件:

[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 
您始终可以根据子组名称使用
webserver
group或individualregion来寻址所有服务器

另一种选择是保留原始剧本,但将执行限制在特定的服务器组:

# my_playbook.yml
---
- hosts: webservers
  serial: 30%

  tasks:

    - include: tasks/deploy-application.yml
然后按如下方式运行ansible playbook:

ansible playbook my_playbook.yml--limit=euwebserver