Launch of an instance and configure as Web Server: using ANSIBLE

Launch of an instance and configure as Web Server: using ANSIBLE

Prerequisites:-

  1. Virtaul Box
  2. RHEL 8 ISO.
  3. I have deployed RHEL ISO and I’ll use it as an ansible controller.

I’ve done the minimal installation, Hence need to install some required packages manually.

Ansible configuration steps:-

  1. In you install rhel 8 with minimal install, you have to install python manually:-
No alt text provided for this image

Why I installed Python?

Because Ansible has been derived from the Python language.

Now we need to install ansible using pip3 (python). How it is getting installed?

Remember we created an additional repo “epel-release-latest-8.noarch.rpm

Let’s install Ansible:

No alt text provided for this image

Problem Statement : Deploy Web Server on AWS through ANSIBLE!

♦️Provision EC2 instance through ansible.

♦️Retrieve the IP Address of instance using dynamic inventory concept.

♦️Configure the web server through ansible!

♦️Create role for webserver to customize the Instance and deploy the webpage to root directory.

Step 1 : install boto and ansible library.

Pip3 install boto3

pip3 install ansible

No alt text provided for this image

Step 2 : key pawan.pem

place the key file in “/etc/ansible/” directory.

change the permission of this file to 400 (read-only).

No alt text provided for this image

Step 3 : configure ansible.

No alt text provided for this image

Step 4 : create directories for playbook, roles and inventory

mkdir playbook roles inventory

Step 5 : download ansible dynamic Inventory script for EC2 in inventory folder.

No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image

Make these file executable:

No alt text provided for this image
No alt text provided for this image

Step 6 : Export your aws credentials

export AWS_ACCESS_KEY_ID="accesskey"

export AWS_SECRET_ACCESS_KEY="secretkey"

export AWS_DEFAULT_REGION="ap-south-1"

Step 7 : create role in roles folder.

ansible-galaxy init ec2
ansible-galaxy init web_server
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image

Step 8 : launch an ec2 instance (Amazon Linux AMI 2)

No alt text provided for this image
No alt text provided for this image
No alt text provided for this image

Step 9 : write playbook for launching ec2 in playbook folder.


No alt text provided for this image
No alt text provided for this image
No alt text provided for this image

Step 9 : configure role for the web_server.

No alt text provided for this image


task code to deploy webserver on AWS

No alt text provided for this image


template for IP and port configuration of webserver

No alt text provided for this image


Handler for the code

No alt text provided for this image


variables for the code

Step 11 : write playbook to configure web_server in playbook folder.

No alt text provided for this image


playbook for webserver configuration

No alt text provided for this image


configure webserver

No alt text provided for this image


configuring…

Note : Don’t forget to allow 8080 port in your Security group.

Here we go, Web Server is ready !!!

http://publicIP:8080

No alt text provided for this image


Sample website launched in the AWS instance.

No alt text provided for this image
Thanks For Reading!!



To view or add a comment, sign in

More articles by Siddhant Sharma

Others also viewed

Explore content categories