Ansible - A guide to get started | Dániel Ernő Szabó | Skillshare

Playback Speed

  • 0.5x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 2x

Ansible - A guide to get started

teacher avatar Dániel Ernő Szabó, Pythonista in the making

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Lessons in This Class

5 Lessons (49m)
    • 1. Ansible Getting started

    • 2. Ansible Facts and filtering

    • 3. Ansible Variable substitution in playbooks and the debug module

    • 4. Ansible Install and Uninstall packages and the usage of notifications and handlers

    • 5. Ansible Simple inventory with python, ans some extra sites

  • --
  • Beginner level
  • Intermediate level
  • Advanced level
  • All levels
  • Beg/Int level
  • Int/Adv level

Community Generated

The level is determined by a majority opinion of students who have reviewed this class. The teacher's recommendation is shown until at least 5 student responses are collected.





About This Class

This class gets you up to speed with the latest version of ansible. Ansible is an automation framework loved by big companies due to the agentless nűature and the ease of usage. The whole goal of the class is to allow you to build your own environment to try out and practice skills related to ansible.

Source for the class:



Meet Your Teacher

Teacher Profile Image

Dániel Ernő Szabó

Pythonista in the making


Hello, I'm Dániel Ernő.

I currently work as a devops engineer. I have several years of experience with various platforms and I'm here to teach some advanced techniques which may attribute your job security ;)



See full profile

Class Ratings

Expectations Met?
  • Exceeded!
  • Yes
  • Somewhat
  • Not really
Reviews Archive

In October 2018, we updated our review system to improve the way we collect feedback. Below are the reviews written before that update.

Why Join Skillshare?

Take award-winning Skillshare Original Classes

Each class has short lessons, hands-on projects

Your membership supports Skillshare teachers

Learn From Anywhere

Take classes on the go with the Skillshare app. Stream or download to watch on the plane, the subway, or wherever you learn best.


1. Ansible Getting started: Hello there and welcome back. This video is going to be a little bit different from the usual videos that you may have gotten usedto from this channel. So basically, I wanted to create some videos about other topics and fight on, but they are kind off related to fight on as I see it. So this video is going to be about answerable and how I have created my That's a home set up which allows me to That's a try out different ideas that are might be needed at my work or I just want to improve my knowledge and keep it up to date. So basically and Zieba is an agent less way off automation so and c o let's see. Ah, uh, Come on, come on. So Ah, this is the official website. If you want, you can browse it. But basically my set up consists off four agents or notes where I'm going to be able to run my automation. So basically the 1st 1 is that you bundle. The 2nd 1 is a debian, and the 3rd 1 is a center wish and what you don't see here is my raspberry pi, which is in the kitchen, but basically they are all related to the small infrastructure that I have. And, ah, these are just, ah, freshly installed operating systems. So I'm going to use the solar party, which is kind of a nice tool, which allows me to, let's say, create Ah, dub bass, actually, ssh environment where I can just simply switch between the different notes where I'm connected toe. So let's hope that this recording doesn't go south south ways because, ah, this is kind of the limit. Asked what my PC can achieve So now if everything is correct, I should be able to connect to my center Wes machine. Yes, I did. Let's go next to the rest Very note that's connected to you. But the node Let's connected the Debian node. So what we should do first when we let's see, try to get family or re danceable history in starts and civil. And as you can see, this as able is not yet installed. All we need to do to install and zebra it's the issue. So as you can see, this is a center, Wes and, um is the package manager, so I am in store and zero And what we are also going to install its fightem by item that will and I think that's it. And ah, the other thing, as the current state off environments which are installed is to note that by default by tone is not available on a day about the system. So that's going to it and just sudo su and up gap in stone on Bytom. So now, as you can see, these machines are running. I hope the recording is fine. So basically what we need to do at first is to create a user which is going to be used across, and this user should be able tow log in without any passwords. So we are going toe set up, ssh key based authentication so that we can ssh toe remote notes without any kind off password entering, and it makes our lives easier. So add user and Zebo and password and zero is going to be as a bill on Z bo And yeah, we know that this is a bad pass for, but this is just the demo and we want to do the we pseudo and with this twisted oh, we would like to find the rope with root and after the throw, we would like toward the end zero user old equals home and no pass word. Oh, now we can exit this one. And, uh, let's do this for the rest. Verify also and user and Zippo The password is answerable just for the demo sick. And here we also do the we pseudo and insert as well. Oh, a course for no purse Third Oh, and we will do it for the U Bahn to system. So basically at User and Zibel and, uh, password is an zero The pseudo no Zippel Oh oh no pass at all And the last one is the being system So we do it a super user and ah and use Ah and zero and people as people. Oh boy, something is wrong I think I have mistyped my preferred again. Yea, So it taps if you type the password correctly Now what? Ah I would like to let say Do is to configure my aunt's ever on the center will stop and I can do it the following way. So let's say I would like to enter super user mode and issued an Zebo their stash version command. As you can see, 7.2 point 7.5 and we have this answerable configuration file. So what I'm going to do is to use the Nano text editor and say that I comment out demon storyline. And this, as a whole side is the That's a heart off sensible where you can define groups and hosts which belonged to specific groups. So you are able to let's hear it for to a bunch of machines with, ah with a group name and and it it's a powerful concept and you should keep it in mind. And we will also commit at the studio user. So what I need to do is to pseudo soup and Z Bo and I need to issued S s age key gem common . We will accept everything as the default. And now, if you check the ssh folder, we will see the following. We have a public and the private feet. And when you are using ssh based authentication, what you need to have on the remote nodes is to copy the public key. And when the agent comes with the private key, the given host is able to verify the identity off the private G due to the mathematical Arboretum's behind this process. So ssh copy idee and what I would like to do is to copy my i d from the center was host to the raspberry and I say it's an Zippel at raspberry. I am great, except it and I'm going to issued and zebras password. And as you can see, the ski was I did and I will need to do it for the want of note. And if it goes Wow, I do it for the baby, a node. And now I'm going to do this for the local host because otherwise it is not going to be able to use these keys for authentication. And ah, now what we can do is toe try to run some encirclement. But before that, we're going to create the hosts fire. So we use the nano a litter but can pick whichever you feel like most comfortable working with, so etc and zebo and hosts. And here what we can do is to let's say, uh, debate everything. But it will not work because I'm not running it as pseudo. So now if we did it. Everything we can say that we have the group called Let's say apt based And here was specified Oneto They're beyond and the Roseberry and we have the M based which is the Santo us or the low coast. It doesn't really matter And ah, we could also specified, um, like this. So you want Oh, you want a? That means Debbie em, Russ Boobery rasp berry and ah, the last three definitions that I have shown you could be used when you have an extra structurally different version off these operating systems And you world, let's say Ellen's them in this way. Now, if everything is working correctly, as you can see, I'm at my Asbel user. Where did Super Party go? So and ah, I can say the following and zebo poor I am being and what it is going to do is tow invoked the ping more you're on the remote machines and if everything is working correctly, it is going to get back a result which is called Pong And, uh, yeah, so physically I have written down some stuff for you, so basically ah, that I had four main modules which you can utilize. And one of those modules is the command. The second is share, the third is the script and the force is the role. So both have their advantages and disadvantages. And I'm going to explain them in a later video to you. But let's say we would like to least some directories. How would we go about that? We would like to use the dash A and after that we specify the directory that we would like to dist. And since we have the sensible user on each off our hosts, we will get back Nothing because the director is empty. But you can see the total is zero and ah, this is how you would run an at command in the remote note what we could also do. It's to say, try to get the content of the war log messages five and ah, this needs, ah, super user access. And it is a little bit tricky to achieve it so and civil war, this a they'll Yes, I am five war long messages and we should see this Commons fail because it says that we got the permission denied message. But if you say that we would up the dash s switch to the answer. But it is going to become the route and it is going to least the directories contents. Ah, in case it has such think. Or it seems, that on my Debian host, something is not working. Um, it's not working because I forgot to add my user. So let's add it. I knew it was supposed to work. Now let's rerun it. And three of these hosts should let's say, go with success and even is going to fail because this director does not exist. But basically you get the idea. So if you have set up properly the Wyss ido with Dash s, which you are able to become a root user and you will get the results accordingly to that, what can we do? We could use, let's say module, which is called user, and this module user is able to create a user for us. So let's say end people test, and this is also going to need root privileges. But if everything works properly, what am I doing wrong? Uh huh. I forgot to give it the argument. So you specified with the dash and tomorrow you and we dash a specified the argument which you want toe Let's they give the more you. And now if I leased my home directory, you can see that the uncivil test you is there is there And, um how do I delete user? So if I am pseudo then I can issue the down user on DSI. Well, that's and what we could do is to, let's say, run this one again. So a very important Ah, let's say ah idea behind answerable is the item potency and I'd impotency means that it is only going toe perform specific operations if they are needed to be performed. So if you let the first time creating user and you should the same command to create the same user, it is not going to do anything because it sees that you there already exists. And, um, the playbooks and other off should be created with this concept in mind because it will save you from lots of trouble later in time. So now, as you can see, since the user from you bento us deleted, it was created. But this is already present on these systems and what we could do is still say that the state across Obss ent and this is going to ensure that this use originated from the systems . And now if I go back to a respirator pie, you can see that the user is not that anymore. What we could do is to let say issue a command, and this common would be the data user and Z bo best. And we would like to become this user. What happens when you want to delete a user which does not exist off course? It is going to fail now. If it is the home, we can see the folder there. But if you would like Toa, let's say create the user and then clean it out as it was supposed to be cleaned out. So now we can see that that is the protests owns that specific folder. So if I say issue disc amand afterwards to clean the user, it should be able to remove the user and related directories very well. It didn't delete it, but it doesn't matter. So technically, this was all I wanted to show you. And, ah, I'm going to create some more videos which are related to answer ball and how you can do stuff with this kind of amazing automation platform. Thank you for watching 2. Ansible Facts and filtering: Hello. That and the white Come back. This video is going to be about facts in an invisible and, ah, these sensible facts are basically information that is collected by answerable in advance before you execute command or playbook and so on. So what you could do is to let's say he would like to configure if a fact is collected or not. And you could do this by the and Z Bo as a both See fg fice And here you could specify the collect underscore fact snow and then it would not connect collect an effect in advance. What you could also do is to specify it in the playbook. So that might be, ah case when you get speed gain by not collecting and effects, because the actions you have performing do not rely on an effect. So, uh, let's say I would like to Ron the following Commons and Z bo oh fish m set up. So what it is going to do is to go over every single host in my answerable, hosts five and collect the facts that are ah provided by those hosts. And if I want to speed up this process, I could say That's just fork equals to four. So what it is going to do is that it is going Teoh spin up threat poor which is going to take Ah, tasks based on the ends, bulk amount and ah, each threat in the pool is going toe Execute the specific task anti Here there are no more tasks and after that the school is shut down. So basically it means that you can speed up. You are execution off these tasks. And, uh, let's say we would lie to together, huh? What should we get it? The invisible all I PV for addresses so about or bash em set up de a filter a course and go So now it should Onley collect the I p before addresses from the specify notes which belonged to the old group. So everything in my host five and what I can also do is to say I would like to get the results in the facts for order. And now what it is going to do is to create this fact folder and populate the folder with files which are related to the group members by name. So let's change the Directorate effects and see what in there. So here we have my Debbie house, the locals, which is Santo s the raspberry. And there you want to. So what's in the U bunt off? Five. As you can see, this is the whole information that I've gathered because I have specified the field. And now what I can do. It's the Pip. Install the jays on my own. If it's not already and start, let's see if I can import it. Oh, so it's by default installed. Cool. So now what I can do is with open you No, no, no, no, no. Open you Boone toe because I mean the facts for they're not with re privileges as Jason five. And ah, I could say that my five acres still Jason five from that read and we will wrap it in the Jason Point loads. And if I see what my fight contents now is that this is the lesser Jason five that I have just read and ah, you could let's a build web application which can represent these in formations as the as Ah, let's a weapon so you could create an inventory of your infrastructure based on the facts that you have gathered, which is kind of a powerful concept, and I have used it previously in my other workplace and it was really fun because danceable was there if fast and ah, we could get a pretty good picture off the infrastructure that we are dealing with at the very moment. So basically, this was all I wanted to show you. If you like this video, give it two thumbs up and subscribe for more. Thank you for watching. 3. Ansible Variable substitution in playbooks and the debug module: hello there and we'll come back in this video. I'm going to show you how you can create the playbook in an zipper. And I'm also going to show you how you can use variable substitution so you can say Let's create Ah, playbook, that is ableto install new package. Make sure it's the latest or remove the package on the specified host and the package can be and should be specified by name. So let's see. All right now, as you already see, I have switched to my answerable user. I'm in the playbooks folder, which is empty, and let's create our install package. Not Yem. Oh, here, As usual, I start with three dashes and well should be. Let's call it change and state off. And this is how you can, Aunt Variables. So here I want my back. It's to oh, us, my state on my host. And ah, what we need to do is specify the hosts and the hosts will come from the very able my host , and we need to make sure that we become, and we also need to make sure that we use the answer user, which we have created if you have not ordered the checked out. See my previous video. I show you the set up as to how you can prepare a literal environment for Ah, that's a experimentation. Full. Here are our tests. That's and our dusk has a name which is kind off the same as the comment. I think that should be good and Yem is going to be used and the name and the state of the package needs to be specified. So my package Andi, my state Uh huh. And, ah! We can also specify another interesting feature which is called the bag. So basically, in order for us to be able to de back anything in the playbook, we need to register the result. So what happened when the playbook was executed? And all we need to do is here we are the register juster line and we name the very Able where we would like toe hold the results and I'm going to call it result and the we called a debug. And here we say war equals results, and basically, that's it. So if everything goes well, what I should be able to do now is since I have specified ah yum. I should be able to install package trickle down it on my post. The West, which is, let's say, answerable, controlled by change it to act and now an zero playbook Install package, GMO dash dash extra wars. And I need to specify my host, which is the Let's, say, a raspberry. I need to specify my package, which is the town. It and I need to specify my state, which is the latest. So, uh, if you use the package manager either AM or apt. Ah, you need to make sure you understand difference between the state latest and the state present because in case if you already have a town of packaging, start, but that's not the latest version of edible is not going to do anything. If you specify, in this case the present state because it only wants to make sure that there is dan it installed. But if you specify the latest, then it is going toe. Let's say upgrade it. So let's ah, check out. If this playbook is working very well and zipper user is not a valid one, why would it not be because it's cold, very multi with the gosh So as you can see, this is happening. And ah, let's check the rez. Very what? What is happening here right now? So we have this vital process that started eating of the CPU. This is the very first version of the rest. Very that was released. And it has been working fine ever since. I think in the past years I needed to rein stall it about three times, but that was because I messed up something. So, technically, you can see here that it is now changing the state of fan up to the latest, and it seems to be installed. So Danet and it's looking. So now how do I exit it? Quit. Okay, so now what I could see is that the D bag move. Your came alive and the airport was captured. And this is the standard output that you would see if you have logged in to the raspberry itself, and he should abdicate installed down. So it says that it's reading the package Lee stands on and force. And then it says that it completed successfully. So if I say I run this playbook again, I I'm sure I will get a different output as this is. Ah, kind off the point off I'd impotency so answerable we'll take a look at the facts and effect to a show that the town it is already installed and it will do nothing. So that's it. Basically, this is all I wanted toe show you. I hope you like it. If you did give it the time's up and subscribe for more. Thank you for 4. Ansible Install and Uninstall packages and the usage of notifications and handlers: Hello there on the work. Come back in this video. I'm going to show you how you can use handlers in the insipid playbook. So basically, handlers are Ah, let's say parts off execution which only come to life when a specific task has succeeded So by before, the definition was like the CEO of a task. And you want to notify Handler that performs the tasks After that, the task successfully I succeeded, failed. Whatever. So there are additional actions to perform when you are running invisible playbooks. So let's create it. Uh huh. Install with and the the GMO. So what we would like to do is to define our playbook is toe say this playbook is about installing Engy next and not if ah Inc handler for Restart the hosts are going to be you pronto. And the remote use that is an civil and the become is yes, and the tusks are the following. The name is too install and Gen x and what we would like to do is to use the apt for you and for the sap mature. We need to say that the name if an genetics the state is latest and we would also like toe . Let's say, uh, issue here, though not if I and in the not if I will say restart and genetics. Mm. And now here comes our handlers, and this handler is going to be cold. Rest start Engine X. And for this handler, we used service for you. And the service module needs the name. Which is that the Engine X and the any Both. Yes. Which makes sure that after every consecutive restart of the specific system, the services automatically started and state restarted. So here is another tricky part. So basically, the skate can be stopped, started and restarted. So if you only defined the started here, it will not Ah issued a restart command. So it's signaling differently based on the state. You specify if, Ah, if you issued ah restarted commander than it is going toe restart the service And if it stopped, it is going to be started. If it's running, it is going to be restarted. So that's kind off the difference here. And uh huh, Let's see if it works. So answerable playbook and install with handler Yemma. So now it should go out to the U Bahn to and it should install the engine ICS. It might take some time. Let's see what the trauma she has to say about this. So it is seems to be working, but that's wait for it. A change running handler dressed art and genetics changed. Okay. And ah, let's see. Uh huh. The soaks, grip and checks where e it seems to be working. So, technically, this is what I wanted to show you. Now, if I want, I can go and uninstall my package. Uh huh. Well, you Well, now it should not be running. Oh, it is running s. Oh, yeah, but it is not installed anymore. Let's see what we can do about that. Good. Ah, what if we change our round book a playbook and simply se Oh, no. Let's create another playbook. And this is going to be called remove with handler, not Thiemo. Uh huh. And for this to work, we should first install back the and the bill. And after the install succeeds, we are going to rewrite this RAM book. So we will not if I the handler before the apte is going to remove this package. So now about removing Angie Knicks and notifying handle four Stop. So notify part should come here. Name disable on stop on genetics. And how do I Yeah, that's really write it to still, we need to make sure it's absent. I just call it remove because we have order. Did say both and anybody? No, I think it stump. And if everything goes right, we should be able to run this No auction detected in tusks. Oh, all right then let's just do it in different way. Cool. So now it is going to remove Engine X. And it is also going to run the handler which disables and stops Anjin ICS. So now if I checked the sea if the engine ICS is running, I should see nothing because it needs what it was supposed to do. So if you like this video, give it a thumbs up and subscribe for more. Thank you for 5. Ansible Simple inventory with python, ans some extra sites: Hello there and welcome back. This is the final video off my answerable small Siri's. So basically what I wanted to show you is to how you can create your own cost free inventory with the help of answerable. And for this to work, we need to install a pipe bomb package. And despite in packages called answerable, CMD be and the sensible see MDB is really fun because it makes it really, really easy to create an inventory. So let's changed the route issued a pip install as it will see em the baby. And basically that's it. And we are going to should oh toe the answer per user And here I am going to issue the following common. So an zero desh m set up best s tree effects or and what it is going to do If everything goes correctly, it is going to collect every factor that is available from the specify nodes based on my hosts file and put them in the facts for order. So now what we can do is use despite among you. And as you can see, it's pretty easy and simple. So I issue the following common. I just replace the folder name with facts. And now I should have this overview that h dama and let's see how big is this? So it's about 200 kilobytes. So now what I'm going to do is download this over you html and open it. So now you can see that this is kind off neat inventory that was created without any hassle . Because if you have, ah, version two Piketon, then you can install the small your and it is going to render this HD on my page. And the what you can see is that you have these filters here and you could say that you want to add additional information to this small table here And if you scroll down, you can see that you have every node and listed here and you could get let's say, interesting informations. So, as you can see, the even to machine is ah, Microsoft hyper re bait to it through a machine. It has one process or one gigabyte from and it has the operating system collected kind off the relevant informations and the network information and some stories information. So basically, this is how you can create a pretty nice inventory. And, uh, I want to show you too webpages where you can go further into this whole answerable round. So docks that as a ball that come And here you will find it sensible documentation. And ah, you can find them with demonstrative inventories, playbooks, more US module documentations and so on and supports. And mm, get a place where I usually go is the answer will galaxy. So physically the sensible galaxy is kind off need, Ah, community powered, answerable ground. And here you will find many, many have for users, and many, many have formal use. That word that's a custom developed for the answer ever toe accelerate the daily operation off administration raters. And I think, Ah, this was all I wanted to tell you. I hope you like this Siri's If you did give it a thumbs up and subscribe for more. Thank you for