Using a Load Balancer
A load balancer can help in improving uptime and distributing requests among droplets. DigitalOcean provides a load balancer with a bunch of features:
- Load balancing algorithms
- Health checks
- SSL redirection
- Port forwarding
The problem here is that there is no Ansible module for load balancers.
How to do it…
- As with previous chapters, we will use the
shell
module and thedoctl
command-line tool to write an Ansible task to create a load balancer:
- name: create a load balancer shell: doctl compute load-balancer create --name lb1 --region blr1 --droplet-ids {{ app_droplet.droplet.id }} --forwarding-rules {{ forwarding_rules }} --health-check {{ health_check }} -t {{ DO_OAUTH_TOKEN }}
A load balancer can support a lot of options, but we have used the bare minimum to make it easier to understand. The name
and region
parameters specify the name and region of the load balancer. The name has to be unique and the region must be the same as the droplets. The droplet-ids
parameter can...