Ansible Automation | How to create EC2 instance using Ansible Playbook in AWS | Ansible Tutorials

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone welcome back in this video we are going to learn how to create new vc2 instance using anable Playbook so if you look at this particular diagram so many of my students have complained in the past that whenever they trying to create a new E2 instance using anible Playbook uh especially when they attach IM am Ro to that ec2 instance they are actually getting into this kind of an issue no handler was ready to authenticate one handlers were checked check your credential okay so basically uh if you would have referred this particular uh Playbook you would be running into that issue so what I have done is I have simplified The Playbook um I posted that article over here so that is exactly what we are going to use in this short video all right so let's get started if you see here I already have anable install and I also have BTO install as well on my ec2 instance yeah I'm already connected to my ec2 instance which is actually running here and you can see here right and then I also have you know uh boto installed here as well so as you all know that boto is a kind of AWS SDK for python so in order for you to authenticate or in order to access aw services using anible we have to have both to install so I also have that install as as well and then I also have am am roll attached to my ec2 instance so I can also show you that real quick so if I take you to AWS console and you can actually see here right so I'm actually using an IM Rule and then I have attached a couple of you know policies okay perfect so that is the requirement let's get started right so we have all the prerequisite everything is taken care um we are just showing you all a very simple playbook in order to create a brand new uc2 instance in AWS Cloud I know this is very simple Playbook maybe in the next video uh we will talk about you know how we can leverage anible role instead of just using anable Playbook uh how we can create anable role in order to uh create a new C so that is something we will see in the next video awesome so uh let me quickly go ahead and then create this inventory file uh I I think I might already have but you can execute this command I think I already have created and you can see here uh you need to create this directory and then make sure uh you edit this file and then add this particular entry right so basically I want to uh you know run the Playbook execution on my local machine itself when I say local machine on this machine so that is why you are adding that entry that's it and then I also have playbooks directory here as well but if you don't have one go ahead and then create the playbooks directory I already have one here okay perfect so now let's go ahead and then create the Playbook but before that right if you look at the Playbook again this is very simple Playbook uh you can see here this is where I have declared you know all the variables which I will be using you know in uh these two task okay and then I also have uh what do you call you know the host is Local Host connection is local I don't need to gather facts and all so all the information is there so let's go ahead and then create uh The Playbook going to go ahead and then copy The Playbook entries over there all right so if you look at the Playbook like I mentioned these are the place you know where we have declared variables which we'll be using down below by double braces and then these are the task so I do have two different task one is for creating Security Group uh for my ec2 instance and then I'm opening up these port numbers and then I'm also adding or creating a new uc2 instance okay I'm attaching the security group to my E2 instance and then these are the other uh you know variables which I will be using while provisioning the E2 instance so the region code Ami ID instance type everything is actually declared over here okay and then we time out is like I'm just kind of giving 3 seconds because uh if you don't give it anything uh it may kind of look like that the Playbook execution is stuck because it would wait until the ec2 instance is fully available and ready and up and running but I don't want to you know wait for that long so I just wanted to wait for like couple of seconds so like 3 seconds and then I want to you know uh come out of the Playbook execution so that's it right it's a very simple Playbook all right so let's go ahead and then make sure we have everything configured so this is actually nothing but the key pair right so which key I wanted to uh connect with so let's say I want to use this key so you can also go ahead and then modify the key and then I wanted to create t. small instance and if you want to give some instance name you can go ahead and then provide and then this is actually a image ID so how do I know the image ID you can also go back to your AWS console a launch instance so I wanted to provision wub 22204 so you can copy this Ami and I'm actually currently under us east1 region so make sure you are in the right region I'm under us east1 so that is the am ID uh I think that is not right but let me go ahead and then modify that so that's it right okay and then as part of the security group I wanted to open these port numbers 2280 and then 8080 and then that's my ESS this is inbound this is outbound perfect and then this is my E2 ins so that's it right so let me go ahead and then save this file and then all we have to do is you know go ahead and then execute the Playbook so anable hyphen Playbook and then provide the Playbook name that's it there you go so it already created this Security Group there you go so it also created the E2 instance as well so we should be able to see that right now let me go into uh AWS console refresh there you go guys do you all see that so right now it is in the process of coming up and this is actually the name of the ec2 instance what we provided in the code you can see here this was the name of the ec2 instance and then let me also uh click on it I know it's going to take few seconds to come up if you wanted to uh check the security group and all you can go to security there you go so this was the security group name and you can also look at uh you know the inbound rules right so these are the port numbers what we have open right there you go guys so that is our ec2 instance which is up on running so yeah so that's it guys you know that's how you can uh create brand new uc2 instance in AWS Cloud using anible Playbook thank you for watching this video
Info
Channel: DevOps Coach
Views: 772
Rating: undefined out of 5
Keywords: Ansible playbook for EC2 creation
Id: ef7qgmEhuks
Channel Id: undefined
Length: 7min 38sec (458 seconds)
Published: Mon Jan 22 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.