Deploy Load Balancer and Multiple Web Servers on AWS through Ansible
Task 3
- Provision EC2 instances through ansible.
- Retrieve the IP Address of instances using the dynamic inventory concept.
- Configure the webservers and load balancer through the ansible role.
- The target nodes of the load balancer should auto-update as per the status of web servers.

Provisioning of EC2 Instances
Ansible Inventory

Firstly we configure the dynamic inventory to fetch instance IP addresses dynamically without going to the AWS Web Console with the help of python code i.e ec2.py.
Code for dynamic inventory
https://github.com/neerajsinghnegi/dyanamic-inventory/blob/main/ec2.py
Why we use python code? Because Ansible is not capable to fetch IP addresses dynamically from AWS instances.

After getting the IP addresses of instances we have to change the dynamic inventory (d_inventory) to static inventory in the ansible configuration file i.e ansible.cfg

and then we have to manually copy and paste the IP addresses in the static inventory i.e hosts.

At last, we configure EC2 instances as Load Balancer and Web server by ansible-playbook.
Output

