Using ansible for deploying applications to aws cloud
Hello guys, in one of my previous post I have explained how can you deploy your simple application to AWS. In that post, we have created an AWS cloud account and then ran an ec2 instance manually using the AWS console UI and then by doing ssh into the machine from our local, we were able to deploy our application to the AWS. But this is not always a best practice to follow. This will be best if we could do this just by running some script once. Actually, there are a couple of services which actually does the same thing for us and makes our life much easier.
Ansible is one of such service which we can use to create & configure AWS. In this post, I will explain how we can use ansible to start an ec2 instance and then deploy our application in that instance and finally terminating the instance when we are done.
Now before we can proceed first we need to know some basic things about Ansible. It is open source automation platform. It is very simple, efficient and powerful. Every ansible script that we run is called ansible play and the yml script is called playbook. Another important thing that we need to know before starting to write a script is modules. Modules are the unit of work that ansible ships out to the remote machine. To configure different services there are different modules. Like for configuring clouds, there are Cloud Modules for configuring clusters there is separate Clusters Module. As in this tutorial, we will be configuring aws ec2 instance so we will be using ec2 module which is listed under clouds module.
Now before we can start we should keep one thing in mind. Python is one of major dependency of ansible so in order to run ansible scripts on your new machine you should have python pre-installed on them. This can be easily done using an amazon machine image of an ec2 instance having python installed in it. So while creating a new ec2 instance using playbook we can give this machine image id which in turn will create our new instance with python installed.
Also, you should create an IAM user with aws_secret_key and aws_access_key which will be required in the scripts and give ansible access to run the scripts on our machine.
So after you have installed ansible on your local and have an aws machine image we can write our first script/playbook to create ec2 instance.
Here is how a basic playbook should look : -
So here in the above playbook there are two tasks first we will be creating an ec2 instance and as you can see it requires some basic parameters that we usually mention in the UI while creating an ec2 instance from the aws console. At the end of the first task, we are giving a command called register this is basically used to store all the ec2 instance details after creating in a variable ec2 which can be used in other tasks in the playbook. Like if in other tasks suppose if we need ip address of the instance just created we can use ec2. Now in the second task, we are waiting for some time so that ssh is up in our new ec2 instance. We can start this playbook by using the following command in our terminal.
ansible-playbook create.yaml
This will start the ec2 instance. You can verify this by going to the aws ec2 dashboard. Now when our ec2 instance has been created we can now deploy our application. One extra thing that we need to before we can run our second script is adding the IP address of our newly created instance in the Hosts file since this will be required in our next play while deploying our application. In this tutorial, we will be using a sample node app that runs on port 3000. We basically want following script to be executed on our machine so first, we need to save this in a file and then we will transfer this script file to our remote machine from local and which in turn will get executed there.
The above script will clone the sample application from github, install node and then run our application in the background.
To transfer and run this script on our remote machine we will use an ansible command called script this command basically do two things, first, this will transfer our file from local to the remote machine and then this will execute this command on our machine. So this proves to be a very handy tool. Here is our second playbook to install and start our application.
You can run this using this command from your terminal
ansible-playbook -i Hosts start-application.yaml
Now you can verify if your application is started or not by opening <ec2-ip-address>:3000 and your application should be running there.
Now only part left is terminating our instance using ansible. So we can use following script to stop our instance. Here in this script, we need to give id of the ec2 instance which you can from the ec2 console or this will be shown while running the first script to create an instance.
You can run the script using this command in your terminal
ansible-playbook terminate.yaml
This is all for this post. Here is the entire source code for this post you can clone this and start playing around. I will try to write about another popular provisioning service Terraform in my upcoming tutorial. Feel free to comment below if you have any query.
Reference
ansible docs
Ansible is one of such service which we can use to create & configure AWS. In this post, I will explain how we can use ansible to start an ec2 instance and then deploy our application in that instance and finally terminating the instance when we are done.
Now before we can proceed first we need to know some basic things about Ansible. It is open source automation platform. It is very simple, efficient and powerful. Every ansible script that we run is called ansible play and the yml script is called playbook. Another important thing that we need to know before starting to write a script is modules. Modules are the unit of work that ansible ships out to the remote machine. To configure different services there are different modules. Like for configuring clouds, there are Cloud Modules for configuring clusters there is separate Clusters Module. As in this tutorial, we will be configuring aws ec2 instance so we will be using ec2 module which is listed under clouds module.
Now before we can start we should keep one thing in mind. Python is one of major dependency of ansible so in order to run ansible scripts on your new machine you should have python pre-installed on them. This can be easily done using an amazon machine image of an ec2 instance having python installed in it. So while creating a new ec2 instance using playbook we can give this machine image id which in turn will create our new instance with python installed.
Also, you should create an IAM user with aws_secret_key and aws_access_key which will be required in the scripts and give ansible access to run the scripts on our machine.
So after you have installed ansible on your local and have an aws machine image we can write our first script/playbook to create ec2 instance.
Here is how a basic playbook should look : -
So here in the above playbook there are two tasks first we will be creating an ec2 instance and as you can see it requires some basic parameters that we usually mention in the UI while creating an ec2 instance from the aws console. At the end of the first task, we are giving a command called register this is basically used to store all the ec2 instance details after creating in a variable ec2 which can be used in other tasks in the playbook. Like if in other tasks suppose if we need ip address of the instance just created we can use ec2. Now in the second task, we are waiting for some time so that ssh is up in our new ec2 instance. We can start this playbook by using the following command in our terminal.
ansible-playbook create.yaml
This will start the ec2 instance. You can verify this by going to the aws ec2 dashboard. Now when our ec2 instance has been created we can now deploy our application. One extra thing that we need to before we can run our second script is adding the IP address of our newly created instance in the Hosts file since this will be required in our next play while deploying our application. In this tutorial, we will be using a sample node app that runs on port 3000. We basically want following script to be executed on our machine so first, we need to save this in a file and then we will transfer this script file to our remote machine from local and which in turn will get executed there.
The above script will clone the sample application from github, install node and then run our application in the background.
To transfer and run this script on our remote machine we will use an ansible command called script this command basically do two things, first, this will transfer our file from local to the remote machine and then this will execute this command on our machine. So this proves to be a very handy tool. Here is our second playbook to install and start our application.
You can run this using this command from your terminal
ansible-playbook -i Hosts start-application.yaml
Now you can verify if your application is started or not by opening <ec2-ip-address>:3000 and your application should be running there.
Now only part left is terminating our instance using ansible. So we can use following script to stop our instance. Here in this script, we need to give id of the ec2 instance which you can from the ec2 console or this will be shown while running the first script to create an instance.
You can run the script using this command in your terminal
ansible-playbook terminate.yaml
This is all for this post. Here is the entire source code for this post you can clone this and start playing around. I will try to write about another popular provisioning service Terraform in my upcoming tutorial. Feel free to comment below if you have any query.
Reference
ansible docs
Thank you a lot for providing individuals with a very spectacular possibility to read critical reviews from this site.
ReplyDeleteBest Hadoop Training Institute In chennai
Great Article
DeleteIEEE Projects for Engineering Students
Final Year Projects for CSE
Needed to compose you a very little word to thank you yet again regarding the nice suggestions you’ve contributed here. aws training in chennai
ReplyDeleteNeeded to compose you a very little word to thank you yet again regarding the nice suggestions you’ve contributed here. aws training in chennai
ReplyDeleteNice post keep do posting The Info was too good, for more information regarding the technology Click
ReplyDeleteBest Amazon web Services Training Hyderabad
Best Salesforce Training
Professional Salesforce CRM Training
Thanks for sharing this coding admin. It helps a lot to me.
ReplyDeleteBest AWS Training in Chennai | AWS Training institutes in Chennai
Thanks for providing wonderful information with us. Thank you so much.
ReplyDeleteAir hostess training in Chennai
Air Hostess Training Institute in chennai
air hostess course fees structure in chennai
air hostess training academy in chennai
Necessary to write that you simply almost no phrase to be able to many thanks all over again about the great ideas here Hosting Wordpress Aws you’ve added the following.
ReplyDeleteI would like to say that this blog really convinced me to update my knowledge about the technology you talk about. Thanks, very good post.
ReplyDeleteweb designing course in chennai
SEO Training in Chennai
Big Data Training in Chennai
Hadoop Training in Chennai
Android Training in Chennai
Selenium Training in Chennai
Digital Marketing Course in Chennai
JAVA Training in Chennai
big data certification in chennai
Let's play together on the website of the online casino BGAOC. great gambling sites Do not miss the chance to win with us.
ReplyDeleteThis is quite educational arrange. It has famous breeding about what I rarity to vouch. Colossal proverb.
ReplyDeleteThis trumpet is a famous tone to nab to troths. Congratulations on a career well achieved. This arrange is synchronous s informative impolites festivity to pity. I appreciated what you ok extremely here
Selenium training in bangalore
Selenium training in Chennai
Selenium training in Bangalore
Selenium training in Pune
Selenium Online training
Great blog!! Worthy information that you shared is very useful for my studies. happy sharing!!
ReplyDeletePython Training in Chennai
Python Course in Chennai
Big Data Training in Chennai
German Language Classes in Chennai
Advanced Java Training in Chennai
Python Training in Porur
Python Training in Tambaram
Excellent post. I learned a lot from this blog and I suggest my friends to visit your blog to learn new concept about technology.
ReplyDeleteAWS Training in Chennai
AWS course in Chennai
DevOps certification in Chennai
DevOps Training in Chennai
Data Science Course in Chennai
Data Science Training in Chennai
AWS Training in Velachery
AWS Training in Tambaram
The Post which you wrote is full of informative and vital blogs. I like it very much. Thank you for your work.
ReplyDeletePHP Training in Chennai
PHP Course in Chennai
Selenium Training in Chennai
Software Testing Training in Chennai
Python Training in Chennai
PHP Training in Annanagar
PHP Training in Velachery
Качественная лед лента разных цветов, герметичные и нет, я обычно беру в Экодио
ReplyDeleteIt was really an interesting blog, Thank you for providing unknown facts.
ReplyDeleteAviation Academy in Chennai
Air hostess training in Chennai
Airport management courses in Chennai
Ground staff training in Chennai
Aviation Courses in Chennai
Air Hostess Training Institute in chennai
Airport Management Training in Chennai
airport ground staff training courses in Chennai
Thank you for your blog. It shines good and I have learned a lot from the blog.
ReplyDeleteAWS Training in Bangalore
AWS Course in Bangalore
Best AWS Training in Bangalore
AWS Training Institutes in Bangalore
AWS Certification Training in Bangalore
AWS Training Center in Bangalore
Gone through your blog recently, its very informative about the technology.I expect the next post in the future.
ReplyDeleteAWS Training in Chennai
AWS Course in Chennai
AWS Training in Anna nagar
AWS Course in Velachery
AWS Training in T Nagar
Devops Training in Chennai
Devops Certification in Chennai
Devops Training in Anna nagar
This blog has very useful information about this topic which i am searching now, i gather some information from reading your blog
ReplyDeleteAWS Training in Chennai
Devops Training in Anna nagar
AWS Training in Anna nagar
Data Science Course in Anna nagar
Data Science Training in Anna nagar
AWS Course in Anna nagar
Thanks for this article, your post helps me to understand the future and career prospects. Keep updating your blog with the latest information.
ReplyDeleteData Science Training Institute in Chennai
Data Science Classes in Chennai
Data Science Training in Tambaram
R Programming Training in Chennai
Data Analytics Training in Chennai
Machine Learning course in Chennai
Machine Learning Training in Velachery
Data Science Training in Chennai
A very nice post. Thanks for sharing such a piece of valuable information...
ReplyDeleteRPA Training in Kalyan Nagar
Data Science with Python Training Bangalore
AWS Training in Kalyan Nagar
RPA training in bellandur
AWS Training in bellandur
Marathahalli AWS Training Institues
Kalyan nagar AWS training in institutes
Data Science Training in bellandur
Data Science Training in Kalyan Nagar
Data science training in marathahalli
We are a part of the success story for many of our customer's successful cloud Migrations.
ReplyDeleteCloud Migration services
Aws Cloud Migration services
Azure Cloud Migration services
Thank you for the informative post about Security challenges in AWS , Found it useful . cloud migration services have now become secured and with no-risk
ReplyDeleteVmware Cloud Migration services
Database Migration services
I have gone through your post and I found it very helpfull. Looking forward to see more post from you.
ReplyDeleteLia Infraservices
I am really impressed with the way of writing of this blog. The author has shared the info in a crisp and short way.
ReplyDeleteCloud Migration services
Best Cloud Migration Tool
instagram takipçi satın al - instagram takipçi satın al - tiktok takipçi satın al - instagram takipçi satın al - instagram beğeni satın al - instagram takipçi satın al - instagram takipçi satın al - instagram takipçi satın al - instagram takipçi satın al - binance güvenilir mi - binance güvenilir mi - binance güvenilir mi - binance güvenilir mi - instagram beğeni satın al - instagram beğeni satın al - polen filtresi - google haritalara yer ekleme - btcturk güvenilir mi - binance hesap açma - kuşadası kiralık villa - tiktok izlenme satın al - instagram takipçi satın al - sms onay - paribu sahibi - binance sahibi - btcturk sahibi - paribu ne zaman kuruldu - binance ne zaman kuruldu - btcturk ne zaman kuruldu - youtube izlenme satın al - torrent oyun - google haritalara yer ekleme - altyapısız internet - bedava internet - no deposit bonus forex - erkek spor ayakkabı - webturkey.net - minecraft premium hesap - karfiltre.com - tiktok jeton hilesi - tiktok beğeni satın al - microsoft word indir - misli indir
ReplyDeleteSuch a useful blog with required information. Thanks for sharing this amazing blog.
ReplyDeleteAWS Certification in Chennai
DevOps Course in Chennai
Great post! I really enjoyed reading it. Keep sharing such articles. Looking forward to learn more from you.Thanks for sharing.
ReplyDeleteReactjs Training in Chennai |
Best Reactjs Training Institute in Chennai |
Reactjs course in Chennai
youtube abone satın al /n trendyol indirim kodu
ReplyDeletecami avizesi
cami avizeleri
avize cami
no deposit bonus forex 2021
takipçi satın al
takipçi satın al
takipçi satın al
takipcialdim.com/tiktok-takipci-satin-al/
instagram beğeni satın al
instagram beğeni satın al
btcturk
tiktok izlenme satın al
sms onay
youtube izlenme satın al
no deposit bonus forex 2021
tiktok jeton hilesi
tiktok beğeni satın al
binance
takipçi satın al
uc satın al
sms onay
sms onay
tiktok takipçi satın al
tiktok beğeni satın al
twitter takipçi satın al
trend topic satın al
youtube abone satın al
instagram beğeni satın al
tiktok beğeni satın al
twitter takipçi satın al
trend topic satın al
youtube abone satın al
takipcialdim.com/instagram-begeni-satin-al/
perde modelleri
instagram takipçi satın al
instagram takipçi satın al
takipçi satın al
instagram takipçi satın al
betboo
marsbahis
sultanbet
takipçi satın al
ReplyDeletetakipçi satın al
takipçi satın al
takipçi satın al
takipçi satın al
takipçi satın al
takipçi satın al
takipçi satın al
takipçi satın al
takipçi satın al
takipçi satın al
takipçi satın al
takipçi satın al
takipçi satın al
takipçi satın al
takipçi satın al
takipçi satın al
takipçi satın al
takipçi satın al
takipçi satın al
takipçi satın al
instagram takipçi satın al
instagram takipçi satın al
takipçi satın al
takipçi satın al
instagram takipçi satın al
instagram takipçi satın al
instagram takipçi satın al
instagram takipçi satın al
takipçi satın al
instagram takipçi satın al
takipçi satın al
ReplyDeleteinstagram takipçi satın al
https://www.takipcikenti.com
Extraordinary post I should state and a debt of gratitude is in order for the data. Instruction is unquestionably a clingy subject. Be that as it may, is still among the main subjects within recent memory. I value your post and anticipate more. data science course in london
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteI owe you a debt of gratitude because the article you've posted here is fantastic about Integrated Payment Systems Singapore. I learned something useful from this article. Thank you for sharing that. Continue to post.
ReplyDeletedent hangi borsada
ReplyDeletesc coin hangi borsada
btt coin hangi borsada
hnt coin hangi borsada
elf coin hangi borsada
psg coin hangi borsada
mdt coin hangi borsada
dot coin hangi borsada
mit coin hangi borsada
tiktok jeton hilesi
ReplyDeletetiktok jeton hilesi
referans kimliği nedir
gate güvenilir mi
tiktok jeton hilesi
paribu
btcturk
bitcoin nasıl alınır
yurtdışı kargo
seo fiyatları
ReplyDeletesaç ekimi
dedektör
instagram takipçi satın al
ankara evden eve nakliyat
fantezi iç giyim
sosyal medya yönetimi
mobil ödeme bozdurma
kripto para nasıl alınır
bitcoin nasıl alınır
ReplyDeletetiktok jeton hilesi
youtube abone satın al
gate io güvenilir mi
referans kimliği nedir
tiktok takipçi satın al
bitcoin nasıl alınır
mobil ödeme bozdurma
mobil ödeme bozdurma
Amazing Test
ReplyDeleteYou have given essential data for us. about best hr software in uae It is excellent and good for everyone. Keep posting always. I am very thankful to you.
ReplyDelete