Ansible Full Course | Ansible Tutorial For Beginners | Learn Ansible Step By Step | Simplilearn

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] answer will provides you with one of the easiest ways to automate your application and i-tree infrastructure on that note hi guys welcome to this complete absolute tutorial by simply learned in this video we'll be covering some of the most important concepts relating to the DevOps tool ansible we take you through how you can install ansible and how you can use the tool to automate your courses first we have one journey to tell us how to install ansible on your system a very warm welcome to all of yours and anjali from simply learn and today I will be showing you how you can install the configuration management tool ansible so let's have a brief about why one would use ansible and what exactly is ansible so if you consider the case of an organization it has a very large infrastructure which means it has more than probably hundreds of systems and giving one or even a small team of people the responsibility to configure all these systems makes their work really tough repetitive and as you know manual work is always prone to errors so ansible is a tool which can automate the configuration of all these systems with an table a small team of system administrators can write simple codes in G Amin and these codes are deployed on to the hundreds and thousands of servers which configures them to the desired States so ansible automates configuration management that is configuring your systems it automates orchestration which means it brings together a number of applications and decides an order in which these are executed and it also automates deployment of the applications now that we know what ansible does let's move on to the installation of ansible so here is my Oracle VM VirtualBox manager I'll be using two systems there's the node system which is basically my client system and there's the server system or the master system so let's begin at a server system so this is my master system guys so the first thing we do is we download our ansible tool so one thing we must remember with ansible is that unlike chef or puppet ansible is a push type of configuration management tool so what this means is that the entire control here lies with your master or your server system this is where you write your configuration files and these are also responsible for pushing these code figuration files onto your node or client system as and when required crepes are ansible tool is installed now we need to open a ansible horse file and there will specify the details of our node offline machine so this sir ansible horse pile as you can see here the entire file is commented but there's a certain syntax that you'd observe for example here we have a group named web servers under which we have the IP addresses or certain hostname so this is about how we'll be adding the details for our client system first we need to give a group name under this grooc basically we add all the clients which require a certain type of configuration since we are using just one node we'll give only the details for that particular node first we need to add the IP address of our client machine so let's just go back to our client machine and this here is the IP address 192 point 168 point two point eleven once you have tied in your IP address give a space and then we'll specify the user for a client machine so all communications between the server or the master system and the client or the node system takes place through SSH SSH basically provides a secure channel for the transfer of information follow this up with your password in my case it's the routes password and that's it we are done so now we save this file and go back to our terminal so now that our hosts file is written the next thing we do is we write a playbook the playbook is the technical term used for all the configuration files that we write in ansible now play books are written in Jamel yea Milles extremely simple to both write and understand it's in fact very close to English so now we'll write a playbook the playbook or any kodi neeya mel first starts with three dashes this indicates the beginning of your file next thing we need to give a name to our playbook so name and I'm going to name my playbook sample book we next need to specify our host systems which is basically the systems at which the configuration file or the PlayBook in our case will be executed so we'll be executing this a decline machines mentioned under the group ansible servers so we had just one line machine under it we will still mention the group name we next need to specify the username with which we'll be logging into our line machine which is root in my case and become true specifies that you need to become the root to execute this playbook so becoming the roots called a privilege escalation next we need to specify our TAS so these are basically the actions that the playbook will be performing so you would have noticed everything so far is aligned that is named host remote user become and tasks because these are at one level now whatever comes under tasks will be shifted slightly towards these right although yeah Mel is extremely simple to understand and read both it's a little tricky while writing because you need to be very careful about the indentations and the spacing so my first task is install httpd which is basically a Apache server so now my commands yam and this will be installing the httpd package and the latest state of it will be installed so that's our first task now our second task would be running our Apache service so named run httpd and the action which is service we'll be performed on httpd hence the name httpd and state must be started now we come to a third task so here we create a very simple web page that will be hosted so create content is the name of a task and the content that we are creating here will basically be copied to a node system at a particular file location that will provide a content will be congrats and then we'll provide the destination at which this file will be copied so this is the default location for all our HTML files and that's it we are done writing our playbook just save this and go back to your terminal before we execute the PlayBook or push the PlayBook on to our north system let's check these syntax of our playbook so the command for doing so is and if everything's fine with your playbook the output would be just your PlayBook name so our syntax is perfectly fine now we can push on the playbook to unknown or the climb machine and that's the syntax for doing so now as your PlayBook is being sent over to the client machine you can see that first the facts are gathered that is the current state of your client machine is first fetched to check what all is to be changed and what is already present so the first thing is installing httpd so our system already had httpd so it says ok because this does not need to be changed on next task was running httpd now although our system had the Apache service it was not running so that is one thing that was changed the next was there was no content available so the content was also added so two tasks were changed and four things were ok now everything seems fine and before you move any forward it is very important that we check this one line of documentation provided by ansible you have all kind of information available here regarding which all tasks were executed if your client machine was reachable or unreachable and so on so now that everything's fine here we can move on to a node system and we'll just go to a browser so if a playbook has been executed here what should happen is that the httpd service must be in the running state and the web page that we created should be hosted so let's just type localhost and great everything's working fine so our web page is displayed here so we come to an end for our installation and configuration video for the configuration management tool ansible if you have any doubts please post them in the comment section below and we'll definitely get back to you as soon as possible thanks Angie now we have Matthew and Anjali take us through how to work with ansible ansible today as one of the key tools that you would have within your dev ops environment so the things that we going to go through today is we're gonna cover why you would want to use a product like ansible what ansible really is and how it's all value to you in your organization the difference is between ansible and other products that similar to it on the market and what make sensible a compelling product and I want to dig into the architecture financeable going to look at how you would create a playbook how you'd manage your inventory of your server environments and then what is the actual workings of answer Bob a little extra we're going to also throw in ansible Tower one of the secret source solutions that you can use for improving the speed and performance of how you create your ansible environments and finally we're going to go through a use case by looking at HootSuite social media management company and how they use ansible to really improve the efficiency within their organizations so let's jump into this so the big question is why ansible so you have to think of ansible as another tool that you have within your DevOps environment for helping manage the service and this definitely falls on the operations side of the dev ops equation so if we look here we have a picture of Sam and like yourselves Sam is a system administrator and he is responsible for maintaining the infrastructure for all the different servers within his company so some of the services that he may have that he has to maintain could be web servers running Apache they could be database servers running my sequel and if you only have a few servers then that's fairly easy to maintain I mean if you have three web servers and two database servers and let's face it when we all love just to have one or two servers to manage it would be really easy to maintain the trick however is as we start increasing the number of servers and this is a reality of the environments that we live and operate in it becomes increasingly difficult to create consistent setup of different infrastructures such as web servers and databases for the simple reason that we're all human as if we had to update and maintain all of those servers by hand there's a good chance that we would not set up each server identically now this is where a sport really comes to the rescue and helps you become an efficient operations team ansible like other system solutions such as a chef and puppet uses code that you can write into bribe the installation and set up all of your servers so you can actually repeat it and deploy those servers consistently into multiple areas so now you don't have to have one person redoing Andry following setup procedures you just write one script and then each script can be executed and have a consistent environment so we've gone through why you'd want to use Hanceville let's step through what a spool really is so you know this is all great but you know how do we actually use these tools in our environment so ansible hat is a tool that really allows you to create and control three key areas that you would have within your operations environment first of all there's IT automation so you can actually write instructions that automate the IT setup that you would typically do manually in the past the second is the configuration and having consistent configuration imagine setting up hundreds of Apache servers and being able to guarantee with precision that each of those Apache servers is set up identically and then finally you want to be able to automate the deployment so that as you scale up your server environment you can just push out instructions that can deploy automatically different servers the bottom line is you want to be able to speed up and make your operations team more efficient so let's talk a little bit about poor configuration and how it works with ansible so there are two different ways of being able to set up different environments for server farms one is to have a key server that has all the instructions on and then on each of the servers that connect to that main master server you would have a piece of software known as a client installed on each of those servers that would communicate to the main master server and then we periodically either update or change the configuration of the slave server this is known as a polka figuration an alternative is a push configuration and the perfect configuration is slightly different the main difference is as with a pull configuration you have a master server where you actually put up the instructions but unlike the pull configuration where you have a client installed on each of the services with a push configuration you actually have no client installed on the remote servers you simply are pushing out the configuration to those servers and forcing a restructure or a fresh clean installation in that environment so ansible is one of those second arounds where it's a push configuration server and this contrasts with other popular products like chef and puppet which having master slave architecture with a master server connecting with a client on a remote slave environment where you would then be pushing out the update with as well you're pushing out the service and the structure of the server to remote hardware and you are just putting it onto the hardware irrelevant of the structure that's out there and there are some significant advantages that you have in that in that you're not having to have the extra overhead weight of a client installed on those remote servers having to constantly communicate back to the master environment so let's step through the architecture that you would have for an answer bowl environment so when you're setting up an ant ansible environment the first thing you want to do is have a local machine and the local machine is where you're going to have all of your instruction and really the power of the control that you'd be pushing out to the remote server so the local machine is where you're gonna be starting and doing all of your work connected from the local machine are all the different nodes pushing out the different configurations that you would set up on the local machine the configurations that you would write and you would write those in code out within a module so you do this on your local machine for creating these modules and each of these modules is actually consistent playbooks the local machine also has a second job and that job is to manage the inventory of the nodes that you have in your environment the local machine is able to connect to each of the different nodes that you would have in your hardware network through SSH clients or a secure client let's dig into some of the different elements within that architecture we're going to take a first look at play books that you would write and create for the ansible environments so the core of an s' wall is the playbook this is where you create the instructions that you write to define the architecture of your hardware so the PlayBook is really just a set of instructions that configure the different nodes that you have and each of those set of instructions is written in a language called Yama and this is a standard language used for configuration server environments did you know that Yama actually stands for a camel ain't markup language that's just a little tidbit to hide behind your ear so let's have a look or one of these play boats it looks like and here we have a sample Yama script that we've written so you start off your Yama script with three dashes and that indicates the start of a script and then the script itself is actually consistent of two distinct plays at the top we have play 1 and below that we have played 2 within each of those plays we define which nodes are we targeting so here we have a web server in the top play and in the second plate we have a database server that were targeting and then within each of those server environments we have the specific tasks that we're looking to execute so let's step through some of these tasks we have an install pachi tasks we have a start Apache task and we have it installed my sequel task and when we do that we're going to execute a specific set of instructions and those instructions can include installing Apache and then setting the state of the Apache environments or starting the Apache environment and setting up and running the my sequel environment so this really isn't too complicated and that's the really good thing about working with young is it's really designed to make it easy for you as an Operations lead to be able to configure the environments that you want to consistently create so let's take a step back though we have two hosts we have web server and database server why do these names come from well this takes us into our next stage and the second part of working with ansible which is the inventory management part of ansible so the inventory part of ansible is where we maintain the structure of our network environment so what we do here is part of the structure in creating different nodes is we've had to create two different nodes here we have a web server node and a database of server net and under web server node we actually have the names that were actually pointed to specific machines within that environment so now when we actually write our scripts all we have to do is refer to either web server or database server and the different servers will have the instructions from the Yama script executed on them this makes it really easy for you to be able to just point to new services without having to write out complex instructions so let's have a look at how as what actually works in real world so the real world environment will is that you'd have the answer for software installed on a local machine and then it connects to different nodes within your network on the local machine you'll have your first your playbook which is the set of instructions for how to set up the remote nodes and then to identify how you're going to connect to those nodes you'll have an inventory we use secure SSH connections to each of the servers so we are encrypting the communication to those servers we're able to grab some basic facts on each server so we understand how we can then push out the playbook to e7 and configure that server remotely the end goal is to have an environment that is consistent so let's ask you a simple question what are the major opportunities the ansel has over chef and pop it really like to hear your answers in the comments below pop them in there and we'll get back to you and really want to hear how you feel as fall is a stronger product or maybe you think it's a weaker product as it compares to other similar products in the market here's the bonus we're gonna talk a little bit about ansible tower so ansible tower is an extra product that Red Hat created that really kind of puts the cherry on the top of the ice cream or is the icing on your cake ansible by itself is a command-line tool however as well Tower is a framework that was designed to access ansible and through the ansible tower framework we now have an easy to use GUI this really makes it easy for non developers to be able to create the environment that they want to be able to manage in their DevOps plan without having to constantly work with the command prompt window so instead of opening up terminal window or a command window and writing out complex instructions only in text you can now use drag and drop and mouse click actions to be able to create your appropriate playbooks inventories and pushes for your nodes alright so we talked a lot about ansible let's take a look at a specific company that's using ansible today and in this example we're gonna look at HootSuite now HootSuite if you not already use their products and they have a great product HootSuite is a social media management system they are able to help with you managing your pushes of social media content across all of the popular social media platforms they're able to provide the analytics they're able to provide the tools that marketing and sales teams can use to be able to assess a sentiment analysis of the messages that are being pushed out really great tool and very popular but part of their popularity drove a specific problem straight to HootSuite the chance they had at HootSuite is that they had to constantly go back and rebuild their server environment and they couldn't do this continuously and be consistent there was no standard documentation and they had to rely on your memory to be able to do this consistently imagine how complex this could get as you're scaling up with a popular product that now has tens of thousands to hundreds of thousands of users this is where ansible what came in and really helped the folks over at HootSuite today the DevOps team at HootSuite right out play books that have specific instructions that define the architecture and structure of their hardware knows and environments and are able to do that as a standard product instead of it being a problem in scaling up their environment they now are able to rebuild and create new servers in a matter of seconds the bottom line is ansible has been able to provide HootSuite with IT automation consistent configuration and free up time from the operations team so that instead of managing servers they're able to provide additional new value to the company a very warm welcome to all our viewers i'm anjali from simply learned and today i'll be taking you through a tutorial on ansible so ansible is currently the most trending and popular configuration management tool and it's used mostly under the DevOps approach so what will you be learning today you'll learn why you should use ansible what exactly is ansible the ansible architecture how ansible works the beta's benefits of ansible and finally we will have a demo on the installation of Apache or the HTTP package on applying systems we'll also be hosting a very simple web page and during this demo I'll also show you how you can write a very simple playbook in Yammer and your inventory file so let's begin why should you use ansible let's consider a scenario of an organization where Sam is a system administrator Sam is responsible for the company's infrastructure a company's infrastructure basically consists of all its systems this could include your web servers your database servers the various repositories and so on so as a system administrator Sam needs to ensure that all the systems are running the updated versions of the software now when you consider a handful of systems this seems like a pretty simple task Sam can simply from system to system and perform the configurations required but that is not the case with an organization is it an organization has a very large infrastructure it could have hundreds and thousands of systems so here is where sans work gets really difficult not only does it get tougher Sam has to move from system to system performing the same tasks over and over again this makes Sam board not just that repeating the same tasks leaves no space for innovation and without any ideas or innovation how does the system throw and the worst of it all is manual labor is prone to errors so what does Sam do well here is where ansible comes in use with ansible Sam can write simple codes that are deployed on to all the systems and configure them to the correct States so now that we know why we should use ansible let's look at what exactly is answered ansible is an IT engine that automates the following tasks so first we have orchestration orchestration basically means bringing together of multiple applications and ensuring an order in which these are executed so for example if you consider a web page that you require to host this web page stores all its values that it takes from the user into a database so the first thing you must do is ensure that the system has a database manager and only then do you host your web page so this kind of an order is very crucial to ensure that things work right next ansible automate configuration management so configuration management simply means that all the systems are maintained at a consistent desired State other tools that automate configuration management include puppet and chef and finally ansible automates deployment deployment simply means the deploying of application onto your servers of different environments so if you have to deploy an application on 10 systems with different environments you don't have to manually do this anymore because ansible automates it for you in fact and simply can also ensure that these applications or the code are deployed at a certain time or after regular intervals now that we know what exactly ansible is let's look at an tubules architecture ansible has two main components you have the local machine and you have your node on the client machine so the local machine is where the system administrator sits he or she installs ansible here and on the other end you have your node or the client systems so in case of ansible there's no supporting software installed here these are just the systems that are required to be configured and they are completely controlled by the local machine at your local machine you also have a module a module is a collection of your configuration files and a case of ansible these configuration files are called play books play books are written in Yael Yael stands for ya man ain't a markup language and it is honestly the easiest language to understand and learn since it's so close to English we also have the inventory the inventory is a file where you have all your notes that require configuration mentioned and based on the kind of configuration they require they are also grouped together so later in the demo we'll have a look at how the playbook and the inventory is written and that will probably make it clearer so of course a local machine needs to communicate with a client and how is this done this is done through SSH SSH is your secure shell which basically provides a protected communication in an unprotected environment ok so we saw the various components of ansible now how this ansible exactly work you have your local machine on one end this is where you install ansible if you've gone through any previous material on ansible you would have come across the term agentless often being associated with this tool so this is what agentless means you're installing ansible only on your local machine and there's no supporting software or plugin being installed on your clients this means that you have not agent on the other end the local machine has complete control and hence the term agentless another term that you would come across with ansible is push configuration so since the local machine has complete control here it pushes the playbooks on to the nodes and thus it's called a push configuration tool now the playbooks and the inventory are written at the local machine and the local machine next with the notes through the SSH client this step here is optional but it's always recommended to do so it's where the facts are collected so facts are basically the current state of the node now all this is collected from the node and sent to the local machine so when the playbook is executed the task mentioned in the playbook is compared against the current status of the node and only the changes that are required to be made further are made and once the playbooks are executed your nodes are configured to the desired States so as I mentioned before ansible is currently the most trending tool in the market under the configuration management umbrella so let's have a look at the beta's benefits of ansible which gives it this position well ansible is agentless it's efficient it's flexible simple yet important and provides automated reporting how does it do all this let's have a look at that agentless as I already mentioned before you require no supporting software or plugin installed a new node or the client system so the master has complete control and automatically this means that ansible is more efficient because now we have more space in our client and node systems for other resources and we can get ansible up and running real quick hansip is also flexible so in infrastructures prone to change very often and ansible takes no amount of time to adjust to these changes and Sybil cannot get any simpler with your playbooks written in a language such as gamal which is as close to English as you can possibly get your important basically means that if you have a playbook which needs to be run n number of systems it would have the same effect on all of these systems without any side effect and finally we have automated reporting so in case of ansible your PlayBook has number of tasks and all these tasks are named so whenever you run or execute your playbook it gives a report on which tasks ran successfully which failed which clients were not reachable and so on all this information is very crucial when you are dealing with a very large infrastructure and finally we reach the most exciting part of our tutorial the hands-on before we move on to the hands on let me just brief you through what exactly will be doing so I'll be hosting two virtual boxes both sent to s7 operating systems one would be my local machine and other my node or the Kline machine so on my local machine first I'll install ansible will then write the inventory and the playbook and then simply deploy this playbook on the client machine there's just one thing that we need to do is that we need to check if the configuration set we mentioned in our playbook are made right so we now begin our demo this my Oracle VirtualBox here I have my master system which is the local machine and this is the client machine so let's have a look at these two machines this is my client machine the terminals opened right now so the client machine terminal has a black background with white text and the master machine terminal has a white background with black text just so you can differentiate between the two so we'll start at the master machine the first thing to do is we need to install our ansible so yum install and spill - why is the command to do so so this may take some time you yeah so ansible installed the next step we go to a host file so whose file here is basically the inventory it's where you will specify all your nodes in our case we just have one node that's the path to your host path as you see everything here is commented so just type in the group for your client nodes so I'm going to name it ant built lines [Music] and here we need to type the IP address of a flying machine so my client machines IP addresses one ninety two point one sixty eight point two point one two seven so before you come to this it's advise that you check the IP address on your flying machine the simple command for that is if config now once you type the IP address put a space and here we need to mention the username and the password for our client so I'll be logging in as the root user so this is the password and then the user which is root in my case that's it now you can save this file just clear the screen next we move on to a playbook we need to write the playbook so the extension for a playbook is why am L which stands for Yamin and as you can see here I have already written my playbook but I'll just explain to you how this is done so a yam L file always begins with three dashes this indicates the start of your gamal file now the first thing is you need to give a name to the entire playbook so I have named it sample book host is basically where this would be executed so as we saw earlier in Iran she I mentioned clients group name as aunts big clients so we use the same name here the remote user is the user you'll be using at your client so in my case that's route and become true is basically to indicate that you need to set your privileges at root so that's called a privilege escalation now a playbook consists of tasks so we have here three tasks the first tasks have named it to install httpd so what we are doing here is we are installing a httpd package which is basically the Apache server and we are installing the most latest version of it hence the state value is latest the next task is running httpd so for the service the name is hash TTP D because that's the service we need to start running and the state is started our next task is creating content so this is the part where we are creating our web page so copy because this is the file that will be created at the client the content will be welcome and the destination of the file will be viable uww HTML index dot HTML as you know this is like a default path that we use to store all our HTML files now as you can see here there's quite a lot of indentation and when it comes to yarmilla although it's very simple to write and very easy to read the indentation is very crucial so the first dash here represents the highest stage that is the name of the playbook and all the dashes under tasks are slightly shifted towards the right so if you have two dashes at the same location they basically mean that they're siblings so the priority would be the same so to ensure that all your tasks are coming under the tasks label make sure they are not directly under name so yeah that's pretty much it so when you write your yeah mel file the language is pretty simple very readable indentations absolutely necessary make sure all your spaces are correctly placed we can now save this file next thing we need to check if the syntax of a Yama file is absolutely light because that's very crucial so the command to check the syntax of the Yama file is ansible playbook the name of your playbook syntax check so we have no syntax errors which is why the only output you receive is sample dot yml which is the name of your PlayBook so our playbook is ready to be executed the command to execute the playbook is ansible playbook and the name of your PlayBook so playbooks executed as you can see her gathering facts that's where all the facts of the note that the present state of the note is collected and sent to the local machine so it's basically to check that if the configuration changes that we are about to make is already made so it's not made we do not have the httpd package installed on our node so this is the first change that's made also if it's not installed of course it's not running that's the second change that's made so it's put into the running state and a final task which is create content is under the okie state this means that the content is already present in the client machine so I made it this way so that you can only see the different states that's present so over here we have okay four so four things are all fine the facts are gathered two things are changed and one is already present to change some it zero clients are unreachable and zero tasks have failed so this is the documentation that I was referring to previously that ansible provides automatically and is very useful as you can see the next step we need to just check on a climber sheet if all the changes that we desired are me so let's move to our client so this my client machine so to check this since we are installing the httpd package and hosting a webpage the best way to do it is open your browser and type in localhost so there you go your Apache server is installed and your web page is hosted thanks guys with that we reach the end of this complete ansible tutorial I hope you enjoyed this video do like and share it thank you for watching and stay tuned for more from simpler [Music]
Info
Channel: Simplilearn
Views: 173,060
Rating: undefined out of 5
Keywords: ansible full course, ansible tutorial for beginners, ansible tutorial, ansible complete tutorial, ansible complete course, ansible crash course, ansible configuration management, ansible training, ansible explained, ansible examples for beginners, ansible training for beginners, ansible training online free, what is ansible, what is ansible in devops, what is ansible and how it works, ansible roles, ansible playbook tutorial, ansible, devops tools, simplilearn
Id: EcnqJbxBcM0
Channel Id: undefined
Length: 40min 42sec (2442 seconds)
Published: Wed Nov 27 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.