How to deploy HAProxy LoadBalancer over AWS in a dynamic way using Ansible Plugins?

Steps to Configure this whole Setup:

  • Setup Dynamic Inventory for AWS Instance using Ansible Plugin.
  • Launch EC2 Instance over AWS tagged for webserver and lbserver using Ansible.
  • Setup Webserver on AWS instance tagged webserver using Ansible.
  • Setup LoadBalancer on AWS instance tagged lbserver using Ansible and also update the webserver IP in loadbalancer config file dynamically.
  • Finally run the playbook, which runs all the roles created using one playbook.

Before start, let’s first set up the local Ansible environment:

  • You can use any Linux Distro for this, I’m using AMAZON Linux here…
  • Upgrade pip version using below command first:
  • Having Ansible installed with Python3. I’m using pip command to install Ansible. After that, you need to create directory and file manually for the ansible config file and inventory file:
  • Setup Ansible config file and Inventory:
  • Now in same directory(/etc/ansible), create one directory for creating Ansible roles and one for ansible inventory file.
  • Install Boto and Boto3 python library:
  • Need one IAM role in AWS because boto can automatically source my AWS API credentials provided by an Amazon EC2 Identity and Access Management (IAM) role to run the playbook.
  • Now our local environment setup is done.

Step 1 - Setup Dynamic Inventory for AWS Instance using Ansible Plugins

Step 2 - Launch EC2 Instance over AWS tagged for webserver and lbserver using Ansible:

Step 3 - Setup Webserver on AWS instance tagged webserver using Ansible:

Step 4 - Setup LoadBalancer on AWS instance tagged lbserver using Ansible and also update the webserver IP in loadbalancer config file dynamically:

Step 5 - Create one playbook to run all the roles created above:

Thanks for reading :)

Feel free to connect on linkedin…😊

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store