Deploy Web Server on AWS through ANSIBLE
Task 2
1. Provision EC2 instance through ansible.
2. Retrieve the IP Address of instance using a dynamic inventory concept.
3. Configure the webserver through ansible!
4. Create a role for the webserver to customize the Instance and deploy the webpage to the root directory.

Provisioning the EC2 instance in AWS
AWS instance launched via ansible-playbook

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.

Output

Github