Deploy Web Server on AWS through ANSIBLE

Neeraj Singh Negi
2 min readOct 12, 2020

--

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

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

static inventory

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

https://github.com/neerajsinghnegi/Ansible-Task-2.git

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Neeraj Singh Negi
Neeraj Singh Negi

Written by Neeraj Singh Negi

AWS | Openstack | GCP | Ansible | Redhat 8 Linux | Docker | Jenkins | Kubernetes | Hadoop | Python | Machine Learning

No responses yet

Write a response