Launching Instance and Configuring the Webserver Using Ansible:-
Ansible and AWS

Launching Instance and Configuring the Webserver Using Ansible:-


Ansible is an open-source automation tool, or platform, used for IT tasks such as configuration management, application deployment, intraservice orchestration, and provisioning. 

Task-

Statement - Deploy Webserver on AWS through Ansible!

♦️Provision EC2 instance through ansible.

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

♦️Configure the webserver through ansible!

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

Let's Start the Practical Part:-

Step1- First of all, we have to install boto before launching the instance.

pip3 install boto 

Step2- Now, we have to create a role for launching the instance on the top of AWS.

mkdir /etc/myroles

cd /etc/myroles

ansible-galaxy init ec2_role
No alt text provided for this image
No alt text provided for this image

Step3- Inside the vars/main.yml file, we have to pass AWS Access Key and Secret Key. Provide Access key inside "myuser" variable and Secret key inside "mypass" variable -

vim  vars/main.yml
   
   myuser: XXXXXXXXXXX
   mypass: XXXXXXXXXXX


Step4- Inside ansible config file.

vim /etc/ansible/ansible.cfg
No alt text provided for this image
cd

vim ec2.yml


No alt text provided for this image

Step5- Now, we have to run the ansible playbook using below command.

ansible-playbook ec2.yml
No alt text provided for this image

OUTPUT OF Step5 -

No alt text provided for this image

Step6- To get the Instance Ip dynamically in the inventory, we have to download ec2.py and ec2.ini files.

mkdir /mydb

cd /mydb

No alt text provided for this image
No alt text provided for this image
Inside ec2.py, just change one line => #!/usr/bin/python3

No alt text provided for this image
export AWS_REGION='ap-south-1'

export AWS_ACCESS_KEY_ID='XXXXXXXXXXX'


export AWS_SECRET_ACCESS_KEY='XXXXXXXXXXX'
No alt text provided for this image

Step7- Now inside the ansible config file, make these changes-

No alt text provided for this image
ansible all --list-hosts
No alt text provided for this image

Step8- Now, for configuring the webserver inside the EC2 instance -

cd /etc/myroles

ansible-galaxy init Webserver
No alt text provided for this image
No alt text provided for this image
cd

vim web.yml 


No alt text provided for this image

Step9- For running the ansible playbook -

ansible-playbook web.yml
No alt text provided for this image

OUTPUT :- Now, on the Browser give the Public IP of the EC2 Instance.

No alt text provided for this image

That's All !!

THANKS FOR READING!!!!

To view or add a comment, sign in

More articles by Megha Varshney

  • Multi Node Kubernetes Cluster Using Ansible..

    What is a Kubernetes Cluster? A Kubernetes Cluster is a set of nodes that run containerized applications. Kubernetes…

    4 Comments
  • How to Configure Web Server Inside the Docker Container by Retrieving Container's IP Dynamically Using Ansible Playbook?

    Task Description 📃:- 🔰Create an Ansible playbook that will retrieve new Container IP and update the inventory. So…

  • GUI Applications On The Top Of DOCKER

    What is Docker? Docker is an open source project that makes it easy to create containers and container-based apps. With…

  • Integration of WordPress with Amazon RDS:-

    What is AWS ? Amazon Web Services (AWS) is a secure cloud services platform, offering compute power, database storage…

  • What is Jenkins and How Netflix uses it?

    Hello guys, In this blog I’m going to explain the automation using Jenkins and a case study on Netflix. But before…

  • OpenShift and It's UseCases

    What is OpenShift ? OpenShift is a cloud development Platform as a Service (PaaS) developed by Red Hat. It’s an open…

  • Simple Queue Service by AWS

    What is SQS? SQS stands for Simple Queue Service. SQS is a managed message queue service offered by Amazon Web Services…

  • Neural Networks

    Neural Networks A Neural Network is a processing device, either an algorithm whose design is inspired by the design and…

  • Azure Kubernetes Service

    What is Azure Kubernetes Service? AKS stands for Azure Kubernetes Service provided by Azure Cloud. It is an open-source…

  • KUBERNETES USE CASES - AIRBNB And PINTEREST

    What is Kubernetes? KUBERNETES is a container management system developed in the Google platform. Kubernetes is the…

    2 Comments

Others also viewed

Explore content categories