Ansible Playbooks for Beginners - Hands-On

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments

This is fantastic. Thank you for finding and sharing this!

👍︎︎ 1 👤︎︎ u/lasercat_pow 📅︎︎ May 21 2020 🗫︎ replies
Captions
you antipope playbooks are an tables orchestration language it is in play books where we define what we want ansible to do it is a set of instructions you provide an table to work its magic so for example it can be as simple as running a series of commands on different servers in a sequence and restarting those servers in a particular order or it could be as complex as deploying hundreds of VMs in a public and private cloud infrastructure provisioning storage two VMs setting up their network and cluster configurations configuring applications on them such as a web server or database server setting load balancing setting up monitoring components installing and configuring backup clients and updating configuration database with information about the new VMs let's take a deeper look at how play books are written remember all play books are written in Yama's format which is why we spent some time earlier getting our hands dirty with Gamal a playbook is a single Yama file containing a set of plays a play defines a set of activities or tasks to be run on a single or a group of hosts a task is a single action to be performed on a host some examples of the tasks are executing a command or script on the host installing a package on the host or performing a shutdown or a restart operation on the host let's take a look at an actual playbook shown here is a symbol playbook that contains a single play named play one the goal of this play is to run a set of activities one after the other on the localhost remember that the host you want to run these actions is defined at the Play level in this case we just want to test on the local host which is why it is set to localhost this could be anything from your inventory file so basically a play is what defines what action you want to do on what hosts all the tasks listed under this particular play will be executed against those hosts and those hosts could be any number of foes or in this case it's just a local host next we run a set of commands one after the other on the host first we print the date then we run a script on the server followed by installing the HTTP package using the yum module and finally starting the web server using the service module now if you don't understand what each of these tasks does exactly and how it is defined don't worry we are going to take a better look at each of these in in a few minutes but for now I just wanted to give you an idea on how a particular antibody book looks let's look at this sample playbook format and try to relate it to what we learned in the yamo section earlier has made a minor change and split the list of tasks into two separate place the ml file which is our playbook contains a list of two plays this is noted by the - so the - indicates that it is an item in the list so the play book is a list of dictionaries in yeah most terms each play is a dictionary and has a set of properties called named host and tasks remember these are properties of a dictionary and so the order doesn't really matter so even if you swap the position of name and host it's still a valid play however this is not the same for task the task as you can see is a list as denoted by the dashes list our ordered collection so the position of entries matter if you swap the position of entries here we are instructing ansible to start the web service first before installing the httpd service which is not a desired solution so the llamo format is key while developing playbooks you must pay extra attention to the indentation and structure of this file the host parameter indicates which hosts you want to run these operations on remember the host you want to perform these operations against is always set at a play level currently this is set to localhost which means that all these actions listed under the task is going to be performed on the localhost you could have any host or group specified here but you must ensure that the host or group is first defined in the inventory file we created earlier the host defined in the inventory file must match the host used in the playbook and all connection information for the host is retrieved from the inventory file now there is no hard rule to use all the host defined in the inventory file you could choose one or multiple or a group or multiple groups from the inventory file in the player but you really don't have to use all of them whatever host you have defined in the play in the playbook should be defined in the inventory file otherwise it's not going to run let's look at what a module is the different actions run by tasks are called modules in this case command script yum and service are all ansible modules there are hundreds of other modules available out-of-the-box information about these modules is available in ansible documentation website or you could simply run the command ansible - doc - L on your ansible system to get familiar with the basic playbook structure in the upcoming exercises you simply need to know the command module later on in the next section we will go through some other basic modules in more detail if you look at the command module you will see that you can simply specify the command you wish to run in this case date and ansible will execute that command on that particular server finally once you successfully build the ansible playbook how do you run it it's very simple execute the ansible playbook command and specify the name of the ansible playbook you just created and that's it if you do a ansible playbook - help you will get to know more about some additional parameters available for this command we will go through some of them in a later section so go ahead and get your hands dirty developing some ansible playbooks encoding exercises we are just going to get you familiar with basic play books and play book structure the whole idea is to get you familiar with how I play is defined and what it is and how tasks are defined and to understand the difference between them we will focus on more realistic use cases in the upcoming lectures but for now we will stick with real basics so check out the upcoming coding exercises section and good luck
Info
Channel: KodeKloud
Views: 108,382
Rating: 4.9546485 out of 5
Keywords: ansible, training, practice, udemy, ansible for beginners, ansible playbook, ansible playbook tutorial for beginners, ansible playbook variables example, ansible for devops, what is ansible, why Ansible, configuration management, configuration management tools, ansible explained, ansible playbook syntax explained, Ansible video, ansible for dummies, learn ansible
Id: Z01b9QZG0D0
Channel Id: undefined
Length: 8min 16sec (496 seconds)
Published: Thu Jun 01 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.