Mastering ansible | Maksym Postument | Skillshare

Playback Speed

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

Mastering ansible

teacher avatar Maksym Postument

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

28 Lessons (1h 33m)
    • 1. Introduction

    • 2. Core Components

    • 3. Ad-hoc overview

    • 4. Ad-hoc demonstration Part 1

    • 5. Ad-hoc demonstration Part 2

    • 6. Inventory Essentials

    • 7. Dynamic Inventories

    • 8. Inventory with variables

    • 9. YAML Inventories Example

    • 10. Dynamic Inventories Example

    • 11. Introduction to playbooks and common modules

    • 12. How to create playbook

    • 13. Syntax Demonstration

    • 14. Use Variables to Retrieve the Results of Running Commands

    • 15. Conditionals and loops

    • 16. Conditionals and loops demo

    • 17. Error handling

    • 18. Error handling demo

    • 19. Tags

    • 20. Tags demo

    • 21. Templates basic

    • 22. Template demo

    • 23. Variables basics

    • 24. Variables demo

    • 25. Facts demo

    • 26. Roles demonstration

    • 27. Galaxy demo

    • 28. Vault demo

  • --
  • 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

Mastering Ansible is a journey of learning Ansible for configuration management and orchestration tool. After this course, you will understand ansible and best practice of usage this awesome tool. You will be able to automate infrastructure configuration and configuration. You will learn how to safely store secure data inside of ansible using ansible vault and how to use community playbooks using ansible galaxy. You will learn how to operate ansible facts how to use facts in ansible conditions. You will learn how to use jinja2 language for template creation and dynamic file configuration using ansible templates

Meet Your Teacher

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. Introduction: Oh, hello. My name is Maxim, and I am develops at 80 Company. Also, I am Red Hat certified engineer and I have few years experience with sensible. And I would like to share with you my knowledge and re sensible best practice. So welcome to my course. 2. Core Components: hello. In this video, I would like to discuss the core components off sensible each of these components we will discuss and much more deeply in the latest video, First of the Invisible Man Components is sensible inventory, and supplementary is just a list of host bus. Store it in the file. It can be any or jahmal format. Ah, by the full and Zimbalist using inventory located at at the end. Zobel Host inventory can contain variables for the specifics. Host and host can be grouped in elementary file. As you can see, here we have two group of host one calls DB and one called its Web server and Coast Group to be contained to host with that, the base host one and that the base hosts two and Web Server contained to host his name, Apache Host one and and UNIX host to a next core component is small. Those models are tour full per particular tasking, answerable each model except parameters and return output in Jason format. And there are a lot of different models in edible. But if some functionality ISS meeting, you can create a model by yourself using bite on language, and here is the example off execution model named Yum Name Parameter is not required, but it's better to have this. One is best practice and it help you to identify. Reach task. Currently in writing a special for the day biking purpose and Yom is the model name, and there are few parameters like name. It's the name off package, which should be install it and state. It described what should be happening with spec. Its present. It's mean back. It should be instant. It can be also absent in this case. Sensible real. Remove current package variables in enjoyable. It's how we deal with difference between system. Ah, variables Name can contain latest numbers or underscore, but should always start with the letter. And valuables can be grouped like by host or by playbook. And variables can be stored in dictionary or in least, and also there is a lot off bread. Define it variables. This is the example off variables in answerable and database. Name is the variable name and test is their value off the variable and for different environment. You can override this variables, so tests and Broad will have different databases created with different users and with different passers. Effect is a special type off invisible variables each time when an Zimbalist execution executed own host for First Desk, which L sensible is doing, is gathering coal. Information about this host in in this example is just a small output off answerable facts gathering. But fix gasoline can be disabled if you need to do it. Playbooks. Playbooks are answerable, configuration, deployment or orchestration. Language playbooks are expressed in Gamel format, and each playbook is composed off one or more place in the least. A za goal off play is to map a group of host to some well defined that rolls represented by sinks answerable. Cold task. You will see this in example, in later video configuration file. It's file, which can override the default behavioral off. Sensible ah instabilities starting toe looking for this file from the top. For example, at the beginning. In looking, it's looking for edible. That's Chief Ji, located in current directory. If this file not existed, started to look for a default danceable configuration file located at sensible see if G and also passed to configuration files can be stored in environment valuables environment. Very configuration file can override many ah default option in sensible by triple seizes in latest video 3. Ad-hoc overview: hello in this section, we're going to discuss Ah, tangible at hook comment and what is that and how you should use it. And what is the difference between at Hawk and playbook and typical models, which can be used with at hook? Comment. So what is at Hook and when you should use it at Hook is just the single module Iran. It can be useful when you need to perform one time desk when you need to run it and and forget about it. For example, it can be used for checking the locks or the managing service, or check for a package of this, instal it or install package or the gathers system. Information in this example. Invisible at hook common is Ron for local hosts to gather host information. Ah, what is the difference between and talk and tangible playbook at Hook? It's run by comment, answerable and playbook is run by common sensible playbook. And as I previously said, a took comment. ISS, useful for one time comment and playbook is effective for a big deployment, orchestration or system configuration. And this is the example off at hook. Comment. Let's talk about Sin Texas a bit. Ah, invisible. This is the common name and minus I is past its mean in voluntary and involuntary is the name of the file and engine ekes is the host name from the inventory file minus m. This means model and apt is the model name minus a is parameters for apt model. So name is the package name and state is the package state after execution Off this comment Ah latest back it off and UNIX will be instal it and minus B it's means become ah, this mean says that comment will be executed to be super privileges. And after execution you will see the result This in green color I mean yellow color. And with this sex success, that means that package was insulin. If that colors will be green, that means that package divorce already instant before comment Execution. Ah, typical models which can be used to be at her comment this pink. It's to Walla date If server is up and it's accessible. Set top is to gather facts about host Yaman Apt is the package manager for redhead and a boon to system services for controlling goddamn ah baggage status. You can restart or stop service Using this model user ISS for controlling system users, user can be removed or can be added. A copy and file is for work with files and folders. 4. Ad-hoc demonstration Part 1: and let's discuss since Texas off at Hook Commons, so instable is just come and we will execute at the at her comment. Flack. I specify for inventory file and currently I'm going to use on my local host machine and this hostess specified inventory file. Next flag is, um, it show which model we're going to use. So currently I'm going to use APT Model and a flag is for argument for four model. For example, let's try to install them and the Knicks package Oh name. It's brackish name and state. It's the package state, so we're going to try to install the latest writers off engine ekes. Let's write in this comment, and we'll see the output. So this come on this file and it's failed because we are trying to install the package a snow on route user to figure this. Errors are one more flag. It's be to become by default. It's route, but it behavioral can be changed using edible configuration file. So now let's try to run this comment with this flag, and as you can see their engine X package voice, install it. So now let's try to remove. Currently, let's try to install this package one more time and let's see what will happen. Ah, come on, Ross. Successful. But nothing goes changed and double checked. If this packages exist and if packages exist and they will just skip this step. So now let's try to change status to absent and see what happened. As you can see the following package Waas removed. 5. Ad-hoc demonstration Part 2: I try to use a few few more and her comment. Let's try to create a file in current directory. It can be created also in remote, but because I'm using is in the my local of'em, it will create it on the host rich. I'm running in the comment. So let's specify their my local host AP address and we're going to use file model. And as argument, we're going to specify on the location when where I want to create this file, I'm going to use the current directory and state. We're going to use the touch. It means that file will Bay created but empty so well. That's right, it's common. And then see that file was created. Let's check the car and directory and file one exists here. What happened? If we will run this comment, why more time for existent file? It will be a recreated because state torture create each time the empty file. So if we will remove this touch, you will just get the information about this file about owner moat and password. This file is located. Ah, let's try to create one more file. We're also going to your storage, but let at here moat and let's try to change moat toe for for for spree was fire was created with more 17 Oh, and this was created this old 444 Also, we can create one more file, but it will be not filed. We can change this. Let's try to remove. We can recon at here absent and this file were removed. What happening around this one more time and a bill check this file. It's not exist, so nothing is removed. 6. Inventory Essentials: in this section we're going to discuss the inventor is what is inventory. Which format can be. Start the inventor refire list difference between static and dynamic inventories, where both inside off inventories and popular option for dynamic inventory. So what is the inventory? Inventories is the least off hosts. Inventory can be located in different location. For example, default location is etc. Instable host. Also, it's possible to specify a location into the inventor reusing flak I in invisible playbook or sensible common and passed to the file name or inventor. Location care can be specified in answerable dot safety file. He also invented can be start as directory, which contains serious off inventory files. On this directory can contain aesthetic and as dynamic inventory. So it's useful when you need to combine like this to type off. Inventor and inventor can be stored in Gamel or any format, and it can be aesthetic or dynamic eso. Let's talk about formats and sort of two possible form. It's and you can see example off is this two formats? First, while it's any and first host one that example that Comets Island group host and it can be cold from NZ Bilic using all or using con group hosts or he isn't directly the host name and observers is hosting Group, which contained the group gold content to host called Don't Get One and Don't Get Too and Web Server wars. It's were variables related to their Web server hosts, and on the right side there is the same inventory but store in the Amel format but most of the time, any format ISS used. So all jahmal inventors should start from all specified by hosts and in this section can be define it on group toasts and section. Children can contain different group of hosts, and here there is the group with Web server, similar to the any form it which contain to Tomcat hosts and, ah, variables related to this hosts. And what is difference between static and dynamic inventory? Static can be in format any or jahmal, but dynamic. It should be executable. It's can be best creep, biting scrip or any other binary and static inventor is maintain it manually. So each time when you add new hosts to your infrastructure, it should be added manually to the inventory file on dynamic Return. J. Stone with inventor information. So which it should automatically locate all new host, which added to the infrastructure and we aesthetic. It's easy to manage static small infrastructure When something changed not very often by dynamic good forest resources, it's suddenly changed. It's good for, for example, for the cloud environment where AP addresses or other host information can be changed very often. And this is the example off aesthetic inventory and variables related toe on this inventory . Like eyes this ah file name inventory, which contained group named Don't get with to host Tomcat one and Tom get to, and this is the ah directory structure. Oh, it's not very good, Teoh. It's not the best practice to store the variables. Insight off them. Ah, inventory. So it's much better to store it in tow Folder, school, group wars and or host. Worse group force is variables related to groups in currently in group folders Or is it Tomcat folder? And all variables from this folder will be available for all Tomcat hosts in host worst various ah variable split it by each host. So if some variables is added to tomcat one that example, that Communist variables will be available on Lee for Tomcat. One that example dot com 7. Dynamic Inventories: Ah, let's discuss dynamic inventory on dynamic inventory. It's executable, and after around this executable, it should be Jason out. Put it into estate out and script mass response like to two parameter minus minus least and minus minus. Host and host name least will display all host with all parameters and host will be display information on Lee for one specific host. And this file's needs to be executable, otherwise answerable will not have permission to run this script. Teoh and get out put And it's this script can be reading on any languages can be biting or Ruby or Java compiler or go compile it or any other language. Ah, on the it should display output in Jason, which form aren't expected by ends Herbal. And there are some popular options which provide you already written the dynamic inventory files. Its AWS is for AWS easy to for rack space for open stacks or in this case, you don't need to implement innocent. You can just go to the AWS easy to dynamic inventory documentation them lord, despite on file or any other language, and store this file into your playbook, location and run playbook. Ah, with flag Minnis minus a and I was like location to this file. And this file will get information about all is it to host which exists and you can run and a bill playbook off on any of this hosts. 8. Inventory with variables: outside to use in my country and winter variables in practice. So here I have inventory file. We is only one and treats ah group called Tomcat but Coast ISS, my local host. And also the arrest to fold their group force, which contains variables file with name Tomcat, which related to host group Don't get and is this file. There is the one variable called Tomcat Port with value 8080 And there is the host Worse with name off. My local host with Elliott Tomcat looks and like this is related. We were going to create file using this valuables. So let's back into our folder, which contained in reentry and let's I try to run and simple comment to shows that variables is used by our host from elementary. So let's run enjoyable at her common from inventory. And we're going to use my host from this inventor or we can use the Group Gold Tomcat And let's run just bash comment. If you run it hook comment. Without Flike m, it will diran as like s bash. Comment. So let's try to run on variable Tomcat port and variable in enviable. Specify it in this way, it's come from gender. Syntex. So let's try to run this comment and check the output. And, as you can see, the value off 808 always displayed. So now let's try to run this government on my host or we can we can use don't get. But let's use model file to create a file with stump cat looks. And in this case, we're going to use sensible variables one more time. Like there is this index and change state toe touch and let's run this. And, as you can see, don't get file was created. Let's try to modify this Tomcat a bit and let's run her own this filed toe check. The content of this file issued removed the model from here. Let's try to run it as you can see. Like location off The file was variable. It was displayed, and we can use the cat to display the content of this file. And of course, you can specify not only host group but Khost name from the inventory file, and it will be the same result 9. YAML Inventories Example: Let's try it. Able to invent Ory file using the Yama Fermat Here we have from the previous video inventory in any format. Let's create the same in when Dre, but on gamma format and all inventor in the Amel format should start with them. Ho all and after that can be host, which contain any number off host. For example, local host, as we have one previous video, but also it can contain the group off hosts. Let's try to create the group don't get, and this group is going to help. Also my workout PC. Let's try to say with Enron the similar seem similar comment from the ah like Esperon on the previous video, but only with the new in wintering and as you can see here, hello World Waas displayed and this is the content of the file list contained. Don't get looks and we can bring the value off this variables, and this is our out 10. Dynamic Inventories Example: Let's try to closer ends a bill dynamic inventory using a rebellious is it to external invent rescript? This is an official answerable documentation leads opened This bridge leads opened this script. Let's go pee All content of this script and sled store this in file called Dynamic that by Let's put content here and I need to change here one line because by default bite on despite and three. And currently I'm using cans. Herbal waste fighting too. So I've changed them. Ah descriptor you spite and took So let's save it. And in order to run the script, this script must to be executable. Let's make this executable and currents group is going to check all A W s host wished exist on my AWS account and perform on this stuff that hosts set up task. Let's try to run it. Let's run at heart comment specified Inventor es then dynamic by and let's run model called Set Up, which is responsible for gathering information and also because it's using ssh to connect to the host. I need to specify the estates user name which I'm going to use to connected this host this government execution should take a few fear second or few minutes is depend How much hostess exist on AWS account? Currently I have only one. So it shouldn't take I too much time. Let's wait. I will follow the video and will continue after this script. Really execute. Oh, as you can see here the script waas executed. And this is the out boot off the all effects which ends a bill is gathered on this host. Yeah. 11. Introduction to playbooks and common modules: I'm pillow in section. We're going to over you that playbook. Have the playbook work. Main common models of Sensible have to create answerable playbook have to use variables, territory, result of friendly commands, conditional and loops in answerable playbooks, our handling and texts. So let's start with their common models. Eso enseval Cora models is models, which all of you to work with file like Korpi Archive Archive. Get your Ellen file modules, which all of you to manage system users and group its user and group model models, which all of you to manage the system. Services like service model Ah, package management model like yum and EPT. And being a model, which all of you to check if the hostess available. Also one of the important answerable models this line in file models. This models all of you to modify, and the configuration or any other text file on the fly and next core models is shell comment and script shall uncommon Olive. You too, Ron. Any shell or even Windows Power Shell comments on the target host and script model is decision to Ron and this script. So was this model will copy script for like your machine to the target machine and execute this script and very important model is the back. The back kiss will all of you to the bark your playbook toe print. Different type off Massachusetts while playbook is executing. 12. How to create playbook: they have to create playbook. A play. It's a map, a group of hosts to define it, rolls and playbook. It's used to orchestrate like complex activity like deployment or configuration. Big infrastructure. And each playbook is region on the Yama language. And here is the example of the basic syntax. All jahmal file should start with three hyphen, and next directive is the host defined on reach Host Display Book should be run. This hostess, taken from the inventory file and remote user, is not required parameter, but you can specify which user to use for ssh connection. And next is the task tasks. Task is defined which actions should be performed or particular host, and first task is install and drinks name. It's not required, but his better toe have, like each task, its name it it will all of you to identify like reached desk ISS writing, and it's very useful for the back purpose. And next it's aped its model name and it's modeler. Except few arguments like Name is the package name and state is the package states or currently after execution off this desk? Ah, latest version off engineers will be instal it and next desk is configuration and Phoenix, it's model is using template model. We will discuss this model in lightest section and the rest like two arguments source and destination sources like the skeleton for for the template and destination. It's destination on Get on the target host where this template should be located and, like this example, is one over the place. So few task is executed on one holds like so that's mean play, and very important that playbook Shin should be important. That's mean, so you can run this playbook as many time as you want to run, and system will not change. So after first execution, engine X will be instal it and configured, and after next execution, nothing will change. 13. Syntax Demonstration: Let's create our first playbook. Currently, I have the, um oh file named Play Yama. Let's start with three hyphen and let's start creating the playbook. So first, what we need at it. Host and currently here I have the inventory file and I have a group apart you. So I'm going to use this group to execute playbook. So let's right here a pageant and next what we need. It's desks desk. It's like the main part off the playbook. Its task is the least off desk, which should be performed on the current host. So let's try to install the app. Parchin. Let's name this desk s install Apache, and I'm using the open toe system. So we're going to use APT model and we need to package name at here, and we need to enter a package state. So we're going to use the latest. And what else do we need here is to add become because I become That means that we're going to use this pseudo because without so the package will not be install it. So next what? When it gets to start the Apaches service. So let's this Let's name this desk start apart you and we're going to use service model for debt. And it also required to arguments. It's the package name and baggage state, and we need to have a package to be started. And we also need to adhere. Become because service was it will be not possible to start results pseudo. And here we have all our small playbook and it, general. It's just the one play because we're executing a few tests on one host. So let's reach to the council and we're going to run this playbook. So I'm going to use that inventor refiled name, inventory and playbook, its name it play. So let's start and wait for result. And like while while this executing you can see that I have output in the cows off. If you would like to have the same our boot, you need to install the big baggage named Cough, say, And after you install this baggage, all answerable output will be risk cuffs. So, as you can see package was, instill it. So let's try to open the page to make sure that a purchase into it. And as you can see like there is the default Apache page so that mean service was instant and started. And let's see what happens if we will execute this playbook one more time. Ah, as you can see here. Ah, desk result was yellow and changed. That means that something was changed in while this desk was executed. But if, like, after next execution way, see that it's green. That means that NASA wants changed while this desk was executed. 14. Use Variables to Retrieve the Results of Running Commands: variables can be used to retrieve the result off running Sensible. A comment. To do that, you need to at Red just world into desk parameters and give this registered name, as you can see here on the example. Ah, after execution off, create test file task. There is the Register World was named file of our So After execution. All output from this comment will be saved in tow. Variables with variable with name, file, war. And after this desk, it's possible to display content of this variables using the back model eso after execution off this desk debark it will display a message. Which message was going to say the back message is, and the content of this variable and as you can see on the a second example, is the like output from from this for comment after the file creation it is going to display addict, we use the all all option on all all staff which model display after its execution. Sometimes it's can be a very long message, and it can look like health whole gone so so in future, we go into discuss, have to like, operate and have to display in less text this output and let's go for a practice 15. Conditionals and loops: in this section, we're going to discuss condition and loops in danceable. Well, let's start from the handlers, handlers, all of you to perform some desk after the target desk returns. Change result. So here we can see this. In example. Ah, like this example, we'll generate template with the name template. At the first execution, this task will return. Results changed. It will be in a hail of color. And this change will trigger this notify cold and UNIX handler. And at the end, off the playbook, this Candler will be cold. And currently our handler is doing engineers restart. So after two template will be generated and change something and the Knicks will be arrest started. And if, like we are going to run this playbook for the second time a template this already existing on the target host on nothing will be changed and engine ekes will won't be restarted. And next part off the condition and loops is conditional. When when is our you too Iran? Ah, that specific task on Lee if condition is true, so currently like the same task and in previous example, which will generate the template. And but he it has additional argument. Call when and it's his value. Config engines, conflict engines. It's a variable. And if, like this variables is do not have, like any value that mean like this task will be executed on Lee if this variables is true or if it's variable exists. But if this variable it's not exist or discuss value, false is this task won't be executed and with items his items is the loop in the answerable . So it will all of you toe have at least least off items and perform some desk for this item . So currently we have also that template model and beheld with items argument and it has some list off while you're called config Juan J to convict a jato. Conflicts reject all this value is a template. This And in the sources there is the answerable variable school item item that mean that this is the item from with item list so it will run like this will create template three time for each item from there was item list. Let's seize this in practice 16. Conditionals and loops demo: Let's try to use condition groups on the practice. Let's start from the handler. Lets create handlers Wisden. A restart about you and we're going to use become because you need to sue the permission to first start service. And we're going to your service model because this model, all of you, ah, to restart any system services and we need state restarted. And of course, we need to add Listen so we can specify this. Listen in Target desk to execute this hander in previous version off sensible, there were no listen options. So you need to always use name. But in the latest, you should use the least so hand lips Australia. Let's create the task. A task is going to create folder and after folder was created, it's going to execute the handler. It's you Stimpy directory and use their one name and we need to notify our restart Apache handler and let's execute. We're going to use that same inventory what we used to before and playbook with his name play Um oh, and let's see the result. A folder will be created, so answerable is going to return. Return start has changed. Oh, we forgot they forgot to add state and thistles. The example off instable error. You can say that file Tempe dearest, Absent cannot continue state absent. So that mean this folder is absent and by the fall, answerable. It's not trying to create on this folder. So we need to specify what I to do directly here. Good. And let's execute this dusk one more time. So now create conflict is going to return. Yellow is a result that me and this result was changed, as you can see, and it executed the handler each time when Handler is executed, it executed at the end of the playbook. So, for example, if they're going to coffee this desk one more time, let's rename there, too. So this dear will be created and let's remove notify from the second task. So only the first task is going to a goal for Handler and let's execute and let's see what happened when, when Handler will be executed, so folder is created. Second folder is created, as you can see, but Handler executed only at the end of the playbook execution. And let's try to execute this playbook one more time to like see how handler is working. If the nothing has changed, status is okay. That mean? Nothing has changed and Handler wasn't executed here. Let's add some additional dusk. Let's try to call his loops was named this task This loops. We're going to use one more time. I the same model. And I'm going to create files in my current directories so I can demonstrate you. And here I am, using the special anvil variable cold item. That means this is the item from the answerable loop and we need to add state Here s touch . And of course, we need to add loops here. Really? Its name it this testify one just filed too. And just file street and let's execute previous step is going to be escaped because we haven't changed nothing. And, like nothing should change that mean it important. And you can see this. These loops was executed three times for each file like file one filed 253 And we can check the current directory that here test file one test file to and test file truly exist. And let's at one more desk to check. Have the condition work. Let's create two different task. Was to different conditions. Let's create Ah condition. Oh, bonte, I'm using the open toe system so instable can detect with which system are we using and depends on the system it can, like, perform different tasks. So am I going to use current directory? And I'm going to create file with name who boom toe here and I'm going to advance condition and enjoyable has after gether. In fact, answerable has built in variable called answerable os family. And we're going to check if this is the day beyond family and let's go pay this desk, rename it condition for ahead. I'm going to create file with the name Redford. And here I'm going to change to direct cat and let's execute, like all previous desk Willers are resolved, nothing changed, but last 21 which will show you in different result on, as you can see here, condition Mobuto status was changed. That mean folder file was created and conditioners head waas skipped because this is a not a redhead system and you can check here in the file system. There is the Mobuto file. It's exist. But nowhere it had filed here 17. Error handling: Let's try to use the register. Can K war? Let's create a simple playbook. For example. This playbook is going to create some file. Let's name it, create file, and we're going to use file model for debt that, Let's specify delegation off this file, which we're going to create. Let's use the TMP folder and name this file test file and state we need to have touched that means that will be created empty file. So let's try to register this. I would put from this comment into variable of his name out put and like what next we need ? It's to display content of this message. We're going to use the back model for that. The but can be used without name or his name. So in this case we're using in the D Block, but result name, and it's required one openess parameter. And let's bring some myself like no buck. My city is and we're going to use and the boat variable s you remember This is their syntax . How edible is handled. This variables. So our example off playbook is ready. Let's switch to them a console and let's try to run the instable comment toe. Check the output on this Gather. In fact, like us, we discussed previously ends abilities gathering all information about the target host and expectancy changes. That means file was created. And you can see the bike messages here that display all information about the file. Who is group? Who is filed? Owner. What kind of permission? This file Hell, where this flight file is located. 18. Error handling demo: but I've handled on practice. So let's create on the test, which is going to, uh, them Lord, some file from the euro. And for that we're going to use Get your own model with two option oneness, Ural, and we're going to specify here you're all for this violet. Let's example at some non existent curole and also destination. It's where this file should be done. Lauded going to your stamp folder and let's try to execute this desk and let's check the result are this task is going to fail? As you can see, uh, from the ordinary name and service. Not known. It means that no exist file one website. But what happens if we are going to adhere? Ignore errors and execute this one more time? Like this desk is still going to fail. But edible mark this desk. It's not favorite, and, as you can see in previous example, fail it here like what's one red? And he'll file. It is zero. And here there is the world ignoring. That means that this desk is ignored and what's difference? Some, if we add some tasks after this get file, even if just get filed, will file. Next desk will be executed. Let's try after that at ah block to check half the try. Catch working, answerable its name it you have to file look, and here we're going to use that block construction, and you don't need to specify the name for the model. Name should be on Lee for the block here. You need to only specify the model that you're going to use various option like we're going to use on the same Euro Fire one and destination. Let it be the same destination, or it can be something different. Its name it and after block, we're going to add the rescue option and this rescue executed only if desk in block ISS failing. So, for example, you can out here some the bark message file not exist. And there is also one more option here. It's always, always is executed every time. Even inevitably, book fail or even if, like execution was successful. Let's let's at here some false a message and let's around the playbooks. First task is going to fail, but because we're using ignore errors, second desk should be executed also, but second task is going to file, too, And as you can see Hugh, get your l file it. But on the day buck message is displayed 19. Tags: and the last part off the playbook section is the text Texas, all of you to Ron specific part from playbook. For example, If you have some very large playbook and you need to modify only one of the component off on this system, it will took too much time to run the whole playbook. In this case, it's possible to use text to limit reach desk. We're going to Ron here and this example, you see, is it Ah, first deskee story start and unique service and this ah module have additional argument cold decks and hit ah Value and UNIX in the Tech and the same desk for extra TB. And but this model Hess, I take festivity, and in this case, you can Iran answerable playbook but specify from common line reach talk you're going to run and only specific desk with the steak will be run. So many tasks, for example, all tasks are lighted to enter. Knicks can have this stack. And if you're on this playbook with this text, Onley tasks related toe and UNIX is going to be around 20. Tags demo: Let's try to your steaks on example. So here I'm going to create the few desk, and I'm going to specify in different Tech Street. So it will see how Texas working. For example, let's create do different text, one with name and UNIX and one with named Apache. And all this task from the stakes will be related to this to system, for example, it begin from the engine Eakes restart. We're going to use service module for that previous to two option name. It's the service name state we need to first started because we're going to restart and let's at Dex here is that it can be a few text, not only one, but I'm going to get just one thick. And let's create the second disc who is the name and fix server, and then go into this file here. Biases where file should be located should be created and state touch that mean file should be created Inlet at here the same tech and let go up in this to task. Let's name it to a party, and we're going to restart Apache and changed Tech and also first service to be able to restart we need to have stood up permission. So become true should be at it here. Let's try to execute the answerable playbook. But specify on Lee one specific deck going to use. Play that, um oh, and here you can specify from common lines hyphen, hyphen, tex and the tech name. And here I'm going to use a party to Tech and let's see off their come onto results. All India Knicks desks should be skipped, as you can see here, but she was restored and a precious ever was. Convict like this to first desk was not display it at all. 21. Templates basic: in this section, we're going to discuss answerable, that templates we're going to talk about them played basic about template model and about template file, which used to like skeleton to generate the rial template. So let's start from the template basics Right then places a file with Jenna dynamically generated and completed using instable variables. Most time templates used in configuration management and the blade protest by using ginger to language eso flats look on the template model Ace Distant play. It is used to generate and deploy the template. The target host and model kits said basic file properties like File owner File Permission. And as our default file properties and template file, this is the example over the template file. Have it's look like, basically, it's just the text file this ginger like specific filters and variables like based on ginger language I template file has extension J two and TEMPLATE has access to the same variables as the playbook. And on this example, we can see example off Web server configuration and after execution off edible template model file will be generated based on this skeleton, but sensible variables will be replace it replace. It is the real value, for example, of several euro will be your elders. Some website, same for user saying for group and answerable, managed available will add like the comments, and this file is managed by enjoyable. So it's better toe, not a did this file directly without answerable and let's see how ends about them play this work on example. 22. Template demo: So let's try to use that template on the practice at the beginning. Let's create few wearables, which we're going to use on inside of a templates like name first and at one more variables is the least value. It will be user list and let's at one more area variable. There isn't the name dead user and get user user for no. So this is our variable. So now let's create the desk, which going to generate and deploy template Uh, let's name it generates template to generate template we're going to use on that template model is required to parameters. One is source. It's the past to the templates. Kill it on file, and I'm going to use my current directory for that template and extension should be J two and destination is that best on get on the target machine where these templates should be deployed, and I'm going to use the same directory but reserved the extension. So let's create here in this directory template is the name template J two, and first, what we can do it, too. Display are and variables so, and it's just the text, and here this is the invisible variable and after execution off this ah part of court will be created the small template with the one line with end and an for value. So it's weight, like just playbook was executed successfully. We can open here template file and you can see that and is like Dev Valium. Ginger Lynn languishes support loops and conditions as regular programming language, so let's try to use a loop inside off ginger template. This is the special sin Texas for ginger loops. So let's create for look for items in and we're going to loop through a user released and we're going to display each item from this list. And let's close for hope. And let's run this comment one more time and let's check the output after that template should be arranged, generated to his new values added to it. So template was generated. Let's close this one and let open. And, as you can see here, this to user while you was displayed also, ginger support. If condition. Let's try to use if conditions so we can use if and to have an variables. And let's check if these variables has value death we're going to bring here and Dave User and we can specify here else we're going to print some some random message. No, let's let spring and environment is not that. And let's close this if condition. So now let's execute this part of coat and let's see, Would you change in the template of template was regenerated land. Open it. As you can see here was displayed value off the Dave User. Uh, what? Let let's change this end of variables to, for example, to cure a and then play it left in the same way. I'm not going to change anything here and let's execute the code one more time and check the results So Tim play but read generated lads closes and let's open and, as you can see was, this part was skipped and this part Waas displayed and you can see here environment. It's not death. Also, Ginger support many other feel till like to convert output to Jason to gamma format, two maps, drink and many others. All this can be written in the documentation. All you can. All this you can read in documentation 23. Variables basics: of whatever you, the variable section here. We're going to discuss sensible variables, answerable dictionary answerable effects and have to use invisible effect. So let's start from the variables. Variables can contain letters, numbers or underscores, but shoots start with the letters where sensible can, where you can define variables in answerable. It can be enforced worse. Fire four folder You can Bram Ah, Veria both while you execute in the playbook it can be done is minus e flag, and you can specify list of variables after these flags. Also, variables can be specified in the roles in the blocks and inventories, and here is the example. Have wearables looks like insensible? And let's switch. There's a dictionary sensible can store the variables in the dictionary. This is the example how dictionary looks like. So here we have users. It's addiction in name and few fuel rally is here. And if you want to go, I have to get access to this variables you can. There is a two way first you can use in this Swiss quotes or you use, or you can use users that name and it will be displayed. The value off name, key and inaudible effects, and we already briefly discuss tangible facts and abilities. Gather facts each time when you execute Interval owned this part if it coast and all facts variable can be used inside of them. Playbook and this is the example have to get out. Put off the invisible AP before Address, in fact, can be used to this condition, for example, ah, as to be sold before some particular task can be executed. If this OS is a winter or is or a threat head or you need to do do configuration off the Web server, you can ah, take the AP address on the fly and replace it inside off the template. Now let's let's look in practice how whereabouts looked like. 24. Variables demo: Yes, well before variables can be showed here in the play directly. Let's create few few variables, and let's try to display the output off this variables. We already so how to use variable in the template section, but let's try to use it inside of depth. Blake. Let's create variable with environment name and let's try to perform some task with this variable. First, let's try to display our boot off this valuable let's create test can display, and we're going to use for that that the back model and we can output here this variable name, but variables should be in votes, and let's try to perform some other desk. Let's try to create for great and fire. Let's use file model here, and this best we're going to specify some location. It's my current directory, and here I'm going to use, like the end variables like it's better to use quotes here, but it's going to work without quotes to and let us to touch state touch. And let's try to execute this playbook. And after execution environment should be like displayed here in screen and into Estelle. Out and file should be created with that name as you can see is the death was displayed here and they have file created. Let's try to replace to this variable, too, as her name and let's try to execute the playbook and let's see the result ends. Abilities. Display this broad value and new file waas created, so it's better to use variable for all for everything. What can be changed between environment so it can will be much easier to manage everything from like the one location you will have, like one file with variables, and you can modify any values there. Do not do not, like, look directly into sensible coat. 25. Facts demo: well, it's still visible Effect in sight, off the right labels and sensible fact. It's information discovered by sensible about the target system, and there is a two way facts. Collect one. It's to using the ad hoc common to his model name set up. And next one, it's Ends. Abilities guesser on this information when playbook is executed and fact gathering can be disabled using gather effects. Attribute. So let's try to execute some common to check the output. And let's try to use our put inside of our playbook. So let's let's try to use our inventory and we can execute set up model here, and this model will gather all available information about the particular host. And let's check the inventory file if I typed it right? Yes, as you can see here and their output. Waas. But there are a lot a lot of our boat, so we can try to our filter something. So let use the same model but, for example, that do the filter and let's try to filter that strike to Finn, filter answerable, and let's see you from think will be displayed. Yep, also, mine information was disabled, but mostly about the invisible and double, and we, for example, we can try and weaken took any variables from here. Let's use edible fight inversion and let's try to used this valuable inside of the playbook . So let's go. Let's create some desks and let's just try to display this message, this play message and we're going to use the back model for from the and we can use sensible, biting version, and we can try to use one more variables. It's just answerable Russian. It also from the facts. And let's try to execute answerable playbook without directly like running the set up model and playbook is now play. Let's let's execute it. And we did some mistake and we forgot. I forgot to add quotes there, so let's execute it one more time. I'm answerable should display the value for this variables. I guess you can see like this to wearables was displayed, but we do not says it's variable anywhere directly into edible playbook. This is how answerable facts can be used. It most time can be mostly can be used with different type of the condition or is ginger templates 26. Roles demonstration: other than the broth sensible rolls is the way have to organize their folders for playbook in file system. In previous example, we define it all variables and desk and everything else here in the main play Jahmal file, but is the best practice to store each my desk and variables and everything else I'll explain. Eat two. Related This rolls from from this file execute only roles. So let's try to create this file structure so folders should be named roles, and it's inside of this rules we can create as Mineiro's as s unit. So let's let's try to create one more folder and this greed there always the name watch here at a party. We're going to create few more folders, so 1st 1 it will be default. Default is their valuables. You can specify where variables in the defaults for the folder that this is the variables. Variables is the lowest priority. So if you specify some valuables here and then, same variables real be specified somewhere else, these variables will be over written. Also, there's important folder with the name desks inside of this folder. There is the main desk. It should be executed also here can be folder. Worse bars is a variable spiced but with higher priorities and in the false. Also, we can store here handlers. We already discussed candles, but it just store handles into separate folders. And also there's should be folder with the name template, and each template should be stored here. Let's drivers creation. Some role in the desks should be created. File raised in I'm name Main Jahmal, and there is the two way Have they organized the structures off tasks can be created directly into Maine. Yama or Main Yama can include some other tasks, so let's try to use in that way. So here we're going to create one more task and it will be named Install Bridget Yama and in May. And really, we are going to include this desk, include desks and his name and still Recchi that, um oh, and here we're going toe installed pension for that, really going to use apt model Chris name, Do and State and still it. Also, we need to create file with a passion configuration. So let's add one more file and let's name it can figure bet she tomo. So let's let's write really name it and let's include it here, off them the configuration. And it should start with hyphen. And here we're going to use the template model toe generate Apache configuration. Let's name it, generate bridge, and we're going to You're scared, that template. And because we're using this structure, we we can specify only the temp light name. We don't need to specify the full allocation off this fire. Let's name it. Gun fee, Operation J two and destination. We're going to store it the team and configuration and J two. And also we're going to use notified here, too. Restart, Apache. Each time one configuration changed. All right. Uh, but so now we need to create this configuration j two template. We're going toe created it inside of the template folder in pullets. Let's at you feel like that bridge configuration, and we need to display some variables here. So in this case, we're going, we're following toe defaults for for them here. We're also going to create the main gammel and include here. Few variables. Let's let's try toe and variables. Next server. You're ill, Reese. Some point and let's at for here. So now we can use all this valuable inside of the template. So let's try to reuse it. Okay. And the same port and also here in Apache configuration were specified. Notify. So we need to create handler. Lets try to create in handle also main jahmal. And let's create this scandal. His name Forest are about you and we're going to give this service model for that. His name attached to and state Reese. I don very start. So here we have, like the typical playbook structure, and now we can try to execute this role to check the output. And we need to include roles here previously reused desk here. But currently we need to specify only their oaths. And we forgot few main point that to restart package, it required pseudo permission. So I need to add become true in tow handlers and the same for I brought you into stuff and ever since credits now. So it's going to execute Rolls Apache on Apache host. So let's try to run sensible playbook and let's see what will happen. It said that we are using results available so dis variable will be ignored. But currently for us, that fine and as you can see here that ends abilities started, including this desk and first was included Apache and a pressure configuration failed because it couldn't find at this configuration. J two. Let's see if I made the mistake in the file name. It should be templates. So let's execute it one more time. And I see I made one my mistake because it's deprecate ID. So we should in Apache. When should replace instal, it reads the present. So let's execute one more time and you can see it started executed desk in that order, which we specified. But, ah, we also made the mistake leads back to the people, restart apart you and we forgot to adhere the listen because it's tried to call this handler. But handler, it's not listened to any desk global, so it not executed. Execution is coming. This issue can see. Ah, template was generated and Handler was not executed because template was generated here in previous play. So what we can do in this case to change destination of this configuration leads. Let's name this file in some other way, and let's start the This is a roll one more time and all this step is. As you can see, it's OK, so it's green. It's playbook, and importance is off after the first execution. You can execute it as many times as you need and nothing should break. And my sense you change. So as you can see, the playbook was executed successfully. Each step was executed, his handler was cold. So when you were working on the invisible playbook is better to organize everything in the roles because it's can save you, like sometime in the biking. And it's much better to split each part off the execution into a logical task. Like Apache configurations. Erica can be some other then played generation, and other staff here can be a some additional about cheap package and modification. Install it and this is the way how to organize. This is the best practice. Have you can use it. And if you are going toe create like roles in this way is this will all of you to lay to publish this rolls into our answerable galaxy, which we're going discuss a bit later 27. Galaxy demo: is it really? They contain many, many different playbooks, and you can go to galaxy dot and supple dot com and your see this website. So here you can type search, and there is them. Search for all acquired for all existed good book. And as against Here's our 70,000 off this playbook, and you can use any off this for free and also you. Can them lord applaud Here you're or own playbook to share it with the community. So answerable galaxy is the tool which comes Instill Itri's sensible and first useful sink , which you can do is the stool. So, for example, you have a Rolls directory, and, of course, it can create the manual in this Apache directory and create all this dark directory inside of this, like roles like Tasks, Default and everything else by their us that much faster way to use sensible galaxy in eat and, for example, we're going to need my sequel role. So let's execute Discover mint and after a few second, my sickle was successfully created, so let's see what exists in this folder. So it's general. It's the same structure which we created before, but this few additional folders and you can like all these files is empty, so you can add You're caught here and this is the one way have to use this answerable galaxy other way. It stood a lot roles directly from from the galaxy. For example, here we have the shower role, and if you will open this role, it will see the minimum interval Russian required for for this role. And there is the way how to install it. So you can just copied this comment and execute it inside of the Your Roles folder, and this role will be and download it and you can include include. So let's let's check. Oh, it's it was them Lord in the default answerable location, the here and now you can specify. And this role, Julian guy, the job. You can specify here into your play ammo, and this role is going to be executed, and Java is going to be install it. But what if you like 40 year environment? You need many different community rules and, like developers, is going to like use different version or different roles. So there is the way half the story arsenic into source control so in their roles folder in it to create file Aries can be any name, but it's like best practice to call it requirements that jahmal And here you can specify s manuals you would like to have. For example, we can include here at the the job Are you can include here one moral that lets took something. Girls, I was back here and let's let's open the Apache So we created this file. Now let's back to the command line and we need to execute edible galaxy Install minus air flag and this requirements jahmal file. And after execution, this roles will be done lorded. But if you already have this roll, them loaded answerable is going t skip Ah, this like parked And after the long did this role you can in include this roll into your ah play Gamel or and execute it to s many host, as you would like to execute 28. Vault demo: It's a bill, old it and sick provide the personal and a bill he has arrested type of. So this is the variable name. So let's Iran. This was Esquimalt bus and again mistake because I forgot to add quotes to variable name. So let's execute one more time. Let's provided the password. And this variable content should be displayed here. Yep. You can see this password is displayed, but it's not very like use useful to enter the passport each time. Especially when you're using some See, I system to run and obliquely books. So in this case, we can create Ah, file is the name name can be other and you can store the password here and you can check the documentation There is Dickie, have which all of you to specify passed to this file so we can use We cannot use making it . Is this one world i d and we're going to use this best words And as you can see here, answerable is not asked for for the passport. But content was display just the way Harv you can use like your secret wearables inside off your indubitably book to be saves that no one came way packet and use your credential. It's a bill, old it and sick provide the personal and a bill Yes, arrested type of. So this is the variable name. So let's Iran this Wiz Esquimalt bus and again mistake because I forgot to add quotes to variable name. So let's execute one more time was provided the password and this variable content should be displayed here. Yet you can see this password is displayed but it's not very like use useful to enter the passport each time, especially when you're using some see I system to run and obliquely books So in this case, we can create Ah, file is the name name can be other and you can store the password here and you can check the documentation There is decay have which all of you to specify pastor this file so we can use we cannot use making it is this one world i d and we're going to use this password And as you can see here, answerable is not asked for for the passport. But content was display just the way Harv you can use like your secret wearables inside off your indubitably book to be saves that no one came way packet and used your credential