LoadBalancer & Web Server configuration in AWS using Ansible

  • Managed Node : system which is managed by controller node, on which ansible run its command to configure
  • Ansible Modules: Modules are libraries which helps us achieve desired purpose. e.g. package module helps us to install Apache Web Server.
  • Inventory: Inventory is the database, where all the managed node IPs are given, which is used by ansible. The path of the inventory file is saved in ansible.conf file which uses it to identify managed node and to access managed node.
  • Tasks: We can create tasks & reuse it.
  • Variables: We can declare the variables to be called in playbook.
  • Playbooks: Playbooks includes configurations steps using which we can provision, configure & manage application deployment.

Task Description :-

Statement :- Deploy a Load Balancer and Multiple Web Servers on AWS instances using Ansible.

Ansible code for launching Ec2 instances
Ansible Playbook execution for ec2 instances
EC2 instance (Web Server)
EC2 instance (Load Balancer)
Web Servers EC2 Instances
wget https://raw.githubusercontent.com/ansible/ansible/stable-2.9/contrib/inventory/ec2.py

wget https://raw.githubusercontent.com/ansible/ansible/stable-2.9/contrib/inventory/ec2.ini
Ansible Config file for getting IP of Web Server Instances
Host List
Connectivity checking between CN & Managed Nodes
Ansible Roles
Web Server configuration Playbook
LoadBalancer configuration playbook
Inventory File
Ansible Config file
set up playbook
Set up playbook execution for Web Server Configuration
Set up playbook execution for Load Balancer Configuration
Load Balancer redirect traffic to different EC2 instance every time
Connecting to Load Balancer using Putty
haproxy.cfg in Load Balancer
Curl command for Load Balancer verification



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