Deploy Web Server on AWS through ANSIBLE

Deploy Web Server on AWS through ANSIBLE

?? Task Description

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!


First we have to install ansible in our controller node through pip3 as is a python module and written in python language.

pip3 install ansible
No alt text provided for this image

For launching an ec2 instance on AWS we have to consider target node same as our controller node. For that we have one IP named localhost which denotes the IP of our controller node only and for checking we can ping to localhost.

ansible localhost -m ping
No alt text provided for this image

So let's start building the playbook which will launch an ec2 instance for us. Before that we have to first install the SDK file so that ansible can go to that AWS account and provision an ec2 instance for us. For that we need to download Boto3 software.

yum install python3

pip3 install boto3

We need to write some code in the configuration file of ansible i.e., ansible.cfg .

No alt text provided for this image

In default section we have provided our inventory file which contains Public IP after the instance gets successfully launched. Then we have host_key_checking = false for disabling the ssh key. To avoid some warning we can use command_warning = false .

To login in that newly launched instance we need to provide its respective key (in my case awsansiblekey.pem) in the read mode for that we have to give execute permission to that key

chmod 400 awskeyansible.pem

The ec2-instance Instances on AWS login firstly into the ec2-user. So we need to give the remote user by remote-user = ec2-user .Then we have to give information of user from which we will be configure it as webserver. If our user is not in the sudoers file then we need to run using sudo command that's why we have become_method = sudo and become_user = root and we can use become_ask_pass = false in case we don't want to use password while login every time.

Now let's begin with the playbook

No alt text provided for this image

Let's run this playbook

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


Let's see whether our instance launched or nor and the IP is copied in our inventory file

No alt text provided for this image

Now lets check our updated ipv.txt file.

No alt text provided for this image


Now let's write a playbook for configuration of httpd webserver

No alt text provided for this image


Let's write our final playbook which will include both the playbooks

No alt text provided for this image

Let's run this playbook

ansible-playbook  aws-as-httpd.yml
No alt text provided for this image
No alt text provided for this image


Simply we can go on google chrome and write our Public IP

No alt text provided for this image


Yay !! We have successfully completed task.??

THANK YOU EVERYONE !!?


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

Aakash O.的更多文章

社区洞察

其他会员也浏览了