Deploy Web Server on AWS through ANSIBLE!

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. 

Provisioning Ec2 Instance:-

First of all we will Provision the Ec2-instance by using Ansible.We can first create a key-pair using Ansible and then we can attach this key to our instance.For this we also have to set the environment variable like this :

$ export AWS_ACCESS_KEY="xxxxxxxxxxxxxxxx"
$ export AWS_SECRET_KEY="xxxxxxxxxxxxxxxxxxxxx"
$ export AWS_REGION_NAME="ap-south-1"


No alt text provided for this image

Now we will run this playbook on localhost

No alt text provided for this image

Now if we go to our was cloud we can see that key-pair has been successfully created

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

Now, We have to create a playbook and then we can create the instance and attach this key-pair for login into the Instance.For this we will again write a playbook and run it by using localhost and configure the Aws ec2 instance.

Now again we need Credentials of the Aws account so we can Secure them by using Ansible-Vault.We will encrypt our credentials with a key and while running the playbook we will provide the key so it will decrypt the credentials and run the task.

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

Now if we go to our AWS cloud we can see our instance has been successfully launched.

No alt text provided for this image

SO Our Instance has been successfully provisioned.Now we have to Create the Inventory file.

What is Inventory in ansible?

ansible inventory is a collection of IP addresses and groups upon which all the commands and module run.We can say its something like IP database.

In this Dynamic World, we can't go manually and fetch the IP Address we use automation to save our time and to develop quickly. Here we have to use a dynamic Inventory Concept to fetch the IP Address.

https://github.com/ansible/ansible/blob/stable-2.9/contrib/inventory/ec2.

Now we will download this file and make this executable and set the environmental variable as mentioned above then if we will run this file so we can see that we can Dynamically get the IP address of the Ec2 instance we also need one more file that is ec2.ini file

https://github.com/ansible/ansible/blob/stable-2.9/contrib/inventory/ec2.ini


Set the Region in which we want to work(i.e. ap-south-1)

No alt text provided for this image

Now we Have to Update our configuration file so that our inventory can be dynamically updated and we can do further things in our instance.

AS we know in Linux Super User is Root and Root can do anything in the system so if want to install something in our system we need to login via root but in general ssh via root is by-default disabled by all the cloud Providers to make the OS very Secure so we will change the privileges of our normal user so that normal user can also perform root tasks .For this we will have to change the ansible Configuration file and update the location of our private key so when the Ip will be fetched we can also ping and perform our tasks.

No alt text provided for this image

Here we have to also tell the inventory file location because it is the one through which our IP will be fetched and here our both the two files resides.

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

So We can now perform the task on our instance by creating the Ansible Playbook.

Now we can configure the web server and put up our code inside the root directory.

No alt text provided for this image


No alt text provided for this image

Now we can see our Website

No alt text provided for this image


Thank You so much for visiting my article!




Ritesh Singh

DevOps Engineer | Graduate Student at Pace University

4 年

well explained....

Onkar Naik

DevOps @Forescout ?? | Google Developer Expert | AWS | DevOps | 3X GCP | 1X Azure | 1X Terraform | Ansible | Kubernetes | SRE | Platform | Jenkins | Tech Blogger ??

4 年

Great work bro ?

要查看或添加评论,请登录

Yogesh kumar Prajapati的更多文章

  • Microsoft automates to achieve more with Red Hat Ansible Automation Platform

    Microsoft automates to achieve more with Red Hat Ansible Automation Platform

    Hello, Connections! In this article, we are going to talk about what is Redhat Ansible and How Microsoft is using…

  • Deploy a Load Balancer and multiple Web Servers on AWS instances through ANSIBLE!

    Deploy a Load Balancer and multiple Web Servers on AWS instances through ANSIBLE!

    Hello connections!!Here is my another task of Ansible! Task Description:- ??Provision EC2 instances through ansible. ??…

    4 条评论
  • NETFLIX ON AWS

    NETFLIX ON AWS

    Netflix is the world’s leading internet television network, with more than 100 million members in more than 190…

  • Big DATA

    Big DATA

    Big Data refers to the amount of huge data that is Coming day by day and large data can not be stored and processed by…

  • Integrating RDS with k8s

    Integrating RDS with k8s

    Hello Connections Welcome to this article! Task Description:- Deploy the WordPress application on Kubernetes and AWS…

  • GCP automation using Terraform

    GCP automation using Terraform

    Hello connections! Welcome this article,we are going to create a Infrastrcture as code. Task Description:- 1.

    5 条评论
  • Automating Cloud infrastructure using terraform (task-4)

    Automating Cloud infrastructure using terraform (task-4)

    Hello, connections! In this article, we will create a highly secure environment in which our site will running in the…

  • Automation using Ansible on Docker

    Automation using Ansible on Docker

    Task description:- Write an Ansible PlayBook that does the following operations in the managed nodes: ?? Configure…

  • Creating website using Terraform with all security appliances

    Creating website using Terraform with all security appliances

    Task Description:- Statement: We have to create a web portal for our company with all the security as much as possible.…

  • Automating web deployment on AWS using Terraform(Task2)

    Automating web deployment on AWS using Terraform(Task2)

    Hello Connections ! Welcome to this Article.In this article i am gonna show you how to deploy an web application on top…

社区洞察

其他会员也浏览了