Automating the Deployment of Web Application by Integrating Ansible with AWS Cloud

Automating the Deployment of Web Application by Integrating Ansible with AWS Cloud

!! ?????????? ?????????????????????? !!

?? Welcome you all to my article based on TASK-2 of RH-294 -Linux Automation using Ansible (RHCE8) Training

?? TASK DESCRIPTION:

?? Launch an AWS instance with the help of ansible. 

?? Retrieve the public IP which is allocated to the launched instance. 

?? With the help of the retrieved Public IP configure the web server in the launched instance. 

In these task we are going to solve one use case based on configuring a web server on AWS cloud and launching one web application by automating all the setup using Integration of Ansible with AWS Cloud .

?? TASK COMPLETION:

1) For AWS Cloud whoever come to them are considered to be a Client .We are going to use Ansible for launching an Instance on AWS Cloud but for that how Ansible will contact to AWS Cloud and Launch the Instance ? . As Ansible use Python libraries behind the scene to configure anything . Hence for AWS Cloud Python has one library called boto which connect the Ansible to contact with AWS API .

? To install boto library use the command -->

 pip3 install boto
No alt text provided for this image

2) To launch an Instance on AWS cloud using Ansible , we use Ansible ec2 module by which Ansible going to launch ec2 instance on AWS . For AWS login we require two types of keys as public access key and secret access key . I make the use of IAM user to create security keys for authentication of AWS account .

No alt text provided for this image

3) For security perspective it is always good to store security credentials in separate files and make the use of variables in main playbook . Here the use of Ansible vault which encrypt the security credential file in which we keep our AWS security keys by specifying variables for it.

To encrypt the the file using Ansible vault use command -->

  ansible-vault encrypt file_name
No alt text provided for this image

4) By using ec2 module in the playbook Ansible can provision ec2 Instance on AWS cloud by using the file named as ansible.yml containing security keys which is encrypted using vault for authentication on AWS cloud .

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

We see in AWS console that ec2 instance is successfully created by Ansible .

No alt text provided for this image

5) Now , we have to configure a web server into launched ec2 instance .For that we have to do SSH login to go inside ec2 Instance .As all these things we going to do using Ansible which requires public ip of ec2 Instance and SSH Private key to login .Since for Ansible ec2 Instance is become a managed node . To contact to managed node Ansible using Inventory file which is provided in ansible.cfg file .But in these TASK we are going to add ec2 instance to the host group of Ansible dynamically using keyword add_host .

This add_host keyword used to add the hosts to ansible inventory file dynamically by creating host group . By using these the IP of ec2 has fetched dynamically and set as host for the Ansible .

No alt text provided for this image

Here the use of keyword with_items gives the output in JSON format and use of keyword wait_for that is to wait for ec2 Instance that they first start port no 22 for SSH login .

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

6) Next step is to login into ec2 Instance via SSH which requires SSH private key and Instance IP .For that the configuration file of ansible should be provided with the private key file .

[defaults]

host_key_checking = FALSE

private_key_file = /root/Ansible-tasks/key17.pem

One more thing is to change the permission of key file as it is by default restricted by some permissions under root user .By changing the permission using following command key file can be used for login by Ansible .

chmod 600 key17.pem

Using the private key file and retrieved public IP of ec2 Instance Ansible going to configure webserver on their manged node i.e ec2 Instance .

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

After successful completion of the Ansible tasks we can see the output by using public ip of ec2 instance whether the webserver is successfully configured or not .

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

We run the ansible playbook which done all the above tasks successfully by using following command .

 ansible-playbook  --ask-vault-pass  playbook_file_name

? One click the the entire set up is done by end to end automation .

No alt text provided for this image

?? In these way I successfully completed the TASK-2 of RH294 - Linux Automation using Ansible (RHCE8) Training .

? I would like to thanks Mr.Vimal Daga for giving such challenging task which helps to explore the core concepts of ansible about integrating it with other technologies .

??For any queries or suggestions DM me .

!! Thanking you all for visiting my article !!

?? Keep Sharing Keep Learning ??








Saurabh Sharma

Open for Contracts | Love Startups

4 年

Great

回复
Priyanka Dabade

ServiceNow Developer | CAD Certified | German A1 certified ????

4 年

Well done!

回复
Ritesh Singh

DevOps Engineer | Graduate Student at Pace University

4 年

well explained bro....

回复
Vishal Dhole

Full Stack Web Developer | Angular | Node.js | AWS | DevOps | Immediate Joiner

4 年

Good work ??

回复
Siddhesh Nalawade

Software Engineer at Sarvaha Systems.

4 年

Nice bro keep it up ???

回复

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

Onkar Naik的更多文章

社区洞察

其他会员也浏览了