简体   繁体   中英

Ansible Rolling Deployment across Multiple Load Balancers

For our production environment, we have load balancers in each region, with multiple webservers behind each of them. We'd like to do a rolling deployment using Ansible across the whole environment, but with the requirement that we don't take down too many servers at a time in each region. Here's an example of our inventory:

[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

And our deploy command:

- hosts: webservers
  serial: 3
  tasks:
    - include: tasks/deploy-application.yml

If we run it like this, it's going to take out all the servers in Europe for the first batch, so we'd have downtime. I know we could reorder the inventory file to make sure the batches work out, but that seems brittle. Is there a better way to do this?

Even if it looks like overkill, the best way would be to divide webservers in groups ( rearrange inventory ):

Example Hosts File:

[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

Playbook:

# 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 

You can always address all servers using webservers group or individaul regions based on subgroup name.

Another option would be to stay with the original playbook but limit execution to particular group of servers:

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

  tasks:

    - include: tasks/deploy-application.yml

And run ansible-playbook as follows:

ansible-playbook my_playbook.yml --limit=euwebservers

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM