Deploying Web server on ec2 instance configured using Ansible

aws ec2 instance using Ansible

Definitions:

Ansible

Ansible is an opensource automation tool used for configuration management and application deployment. It is used for configuring and deploying packages at a system remotely with the use of SSH and SCP protocols.

Ec2

AWS provides a variety of services through its cloud platform. ec2 instances are dynamically allocated systems with customize-able configuration that enables us to host multiple system servers.

About the project:

The project aims at creating an Ansible playbook that makes uses of 2 roles that is used to log into the aws profile and launch ec2 instances and deploy Apache httpd server and host a web page.

Prerequisites:

boto3 and boto packages of python

ec2.py file that can be downloaded from here

AWS account

Procedure:

ansible configuration file

Ansible configuration file needs to be updated to add the location of the role and the key file. The following changes are made at /etc/ansible/ansible.cfg file. The roles are created in /etc/ and the key file is kept at /root/task2/key.pem file.

Next step involves creating a role named myrole, that contains the tasks for logging into the AWS account with the access key and the secret key and then taking these information to the key.pem file and finally starting an ec2 instance of the given type in the given security group.

roles
roles

Then the playbook needs to be written names cloudlaunch.yml. This is the main file of the project and needs to be run, the other 2 roles are mentioned in this playbook and is used to give flow to the two roles mainly.

The boto and boto3 packages need to be installed next and the ec2.py file needs to be downloaded and its location updated in the inventory.

boto boto3 package installation

Next, the webserver role needs to be created and written. This is a basic playbook that installs the apache httpd package, copies a text into the /var/www/html folder and starts the service.

ec2 playbook

Finally the code is run and the playbook executes without any errors.

webpage

The webserver is successfully setup!

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Install Micropython on Nodemcu in simpleway

How to Migrate Mendix 7 to 8

An Introduction to AWS EC2 Instance

Mockito: Emule static or object creation

Chapter 02 — Classes and Objects

We cut our AWS bill by 65% after moving to Lambda — Part 1: it’s not for everyone

How do AWS developers manage Web apps?

Kotlin: First Impressions

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Abhiroop Bas

Abhiroop Bas

More from Medium

AWS Instance Metadata Service: A Quick Refresher

Create your first AWS EC2 instance (Virtual Machine) using a free tier account.

Step-by-step guide to create an autoscaled GitLab runner on AWS

Automate Image Creation with AWS EC2 Image builder