Web Server on AWS through Ansible

Ashwani Singh
3 min readMar 2, 2021
Integration of AWS & Ansible

Set Up AWS CLI on RedHat Linux 8

Configure your AWS user in CLI

Here we will use the concept of dynamic inventory so that in one click we will launch an AWS instance and for configuration purpose it will dynamically put that instance public IP Address into the ansible inventory.

Ansible Configuration File :

Requirements to use AWS using ansible :

boto

boto3

ec2.py

ec2.ini

🔅Setup ec2.py & ec2.ini just by downloading them & giving path of ec2.py in ansible.cfg because they are capable to detect the IP of all the running instances from our AWS Account.

We also export our AWS_ACCESS_KEY & AWS_SECRET_KEY in Base OS.

Run ansible all --list-hosts after setup to get output

🔅Provision EC2 instance through ansible & here we are using vault to store AWS Access Key & AWS Secret Key.

ec2.yml

🔅Configure the web server through ansible

Step by step execution :

No instance running over AWS.

Test ansible inventory

Run Playbook to launch an AWS Instance & print their public IP.

ec2.yml

Check running instances using ansible command & then verify it from EC2 Dashboard of AWS Console.

Now its time to configure webserver on that instance using Ansible Playbook.

web.yml

Web Page that we will deploy on Webserver.

index.html

Run web.yml to configure that instance.

Test the webserver from terminal using curl command.

Thank you so much for reading !!!!!!!

GitHub Repo URL : Click Here

--

--