Book Image

Ansible 2 Cloud Automation Cookbook

By : Aditya Patawari, Vikas Aggarwal
Book Image

Ansible 2 Cloud Automation Cookbook

By: Aditya Patawari, Vikas Aggarwal

Overview of this book

Ansible has a large collection of inbuilt modules to manage various cloud resources. The book begins with the concepts needed to safeguard your credentials and explain how you interact with cloud providers to manage resources. Each chapter begins with an introduction and prerequisites to use the right modules to manage a given cloud provider. Learn about Amazon Web Services, Google Cloud, Microsoft Azure, and other providers. Each chapter shows you how to create basic computing resources, which you can then use to deploy an application. Finally, you will be able to deploy a sample application to demonstrate various usage patterns and utilities of resources.
Table of Contents (11 chapters)

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...

  1. As with previous chapters, we will use the shell module and the doctl 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...