The YAML file explained | YAML Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
if you've been in the it field for any time now then chances are you've run into the yaml file at some point this configuration standard is becoming more and more popular every day tools like ansible kubernetes and docker all make use of this popular format if you're watching this video right now chances are you've run into a yaml file yourself and although a lot of them can look big and scary they can actually be broken down and read quite easily you just need to know the basics in this video i'm going to go over everything you need to know about reading a yaml file i'm also going to include a python script and yaml files that you can go over yourself let's go ahead and have a look at a yaml file right now so yaml files will commonly start with three dashes and end with three dots this is to indicate the start and end of yaml data and it allows you to have multiple sets of yaml data within the same file however these three dots and three dashes are completely optional and aren't always used so with yaml data we have key value pairs the entries in blue are the keys and to the right of them are the values the types of values you can have are strings integers floats booleans arrays or lists and then finally dictionaries let's have a look at the first key value pair here we have a key that is named name and the value is a string of devops journey after that we have a subscriber count which is interpreted as an integer and then we have a boolean value this could be true or false and then we have an example of a float which is just a number with decimal places after that we have an example of a list as well as a nested dictionary so to have a look at those let's load up visual studio code alright so when you're first getting started with yaml i recommend using a code editor that recognizes yaml files something like visual studio code is very good for going over these xaml configuration files i use the extension called yaml and this provides really great syntax highlighting all right so we're in visual studio code here and we have the yaml file loaded up here myfile.yml now yaml files can have the extension.yml or dot yaml it doesn't really matter the next thing is this string that i went over earlier yaml is able to automatically detect the data type whether it's a string or an integer so you actually don't need the quotations you can take the quotations out and you can see that it still recognizes this as a string you can also have single quotations so that works as well the only real time where you need the quotations is if you have an integer that needs to be interpreted as a string so maybe something like this could happen this one's just a boolean it can be true or false you can see the key here is awesome so our channel is awesome so we're setting that to true all right so underneath that we have pi which is just a float pretty basic there after that we have our list one thing i want to note here is you should see the chevron signs if you have that yaml extension installed and this is going to let you minimize groups of items so you can see that topics contains four items within its lists you can actually minimize this to hide it and we can do that with these groups here and it just sort of lets you visualize the data a lot easier so let's go back to topics here so as you can see everything is indented and the indentation allows yaml to interpret the data properly one thing to note with lists is each item is going to have a dash and that separates the elements so you can see each dash indicates a new item in the list so we have four items so moving on the next element within our yaml file is this item name playlist this is a dictionary so a dictionary contains elements that have other elements within it so this dictionary has two elements the first one is docker course and the next one is ansible course so these are key value pairs and the values within them are these two attributes so we have an attribute called link here and then one called videos and you can name these whatever you want so the important thing to understand here is yaml is very versatile you have lists you have dictionaries and you can nest things within each other when we look at the other yaml examples you're going to have a much better understanding of how the nesting sort of works so let's go ahead and do that but before we do that let's have a look at the python script that i created that allows us to read yaml files and if you don't understand python that's not really important you can actually skip this section if you want to but basically this is just a script that i created it's in the description below on github if you want to use this for your own purposes but basically what it does is it takes in a yaml file and reads it and outputs it to the console so let's open up a console here and i'm going to go python read underscore yaml and then i'm going to specify a file name so i'll go myfile.yaml so you can see that it read the yaml file and it was able to interpret the values just going over it we have the name the subscribers the boolean value we got the float here topics which is a list and that came up as a list in python and then we had playlists which is a nested dictionary so this is just a very good little clean script that i created to help me interpret yaml files so let's go ahead and have a look at another example of a yaml file i have three additional example files one is for kubernetes one is for ansible and one is for docker compose so let's have a look at this file it's actually pretty big and a little daunting when you first look at it but let's just go through it and you'll sort of understand how it works all right so just a brief summary on how docker compose works basically what it does is it reads yaml files and then it launches docker containers based on those yaml files so we have this docker compose file opened here and i'll just go over it so the first entry is just a single string of version and then a number so we won't worry about that where most of the data is is it's nested underneath this services object so i'm just going to minimize that and then you can see that it also specifies volumes and then indented under that we have three separate volumes pretty minimal configuration for the volumes so i'll minimize that and then i'll go back into services and then you can see we have influx db chronograph and grafana and basically these are the three containers that docker compose is going to launch so to see that more easily you can minimize it and then you can see underneath services there's three different objects and if you expand it you can see the exact configuration for that object so influx db uses the image of influx db and then it listens on port 8086 it's using this volume and it has these environment variables we can look at grafana now and you can see it sort of has the same configuration but the values within that configuration are different so it's listening on port 3000 it's using the image of grafana and then the environment variables are specific to grafana so to read this and interpret it you don't really need to be an expert on docker compose or anything like that you can just sort of look at this and get a good idea on how it's configured now i do have two more files in there there's my pod which is a kubernetes yaml file for launching pods and then we have an ansible playbook i'm not going to go over this it's pretty simple to understand but if you want to have a look at them it's in the code repository in the description below so go ahead and check them out just have a look and play with them you should sort of be able to read and interpret them and make any changes that you want alright so that's it for today thanks so much for watching if you found the video enjoyable at all please go ahead and hit that like button and if you're interested in learning more about devops programming or just anything it related go ahead and check out the other videos on my channel thanks so much for watching and i hope to see you all in the next video [Music] you
Info
Channel: DevOps Journey
Views: 72,703
Rating: undefined out of 5
Keywords: how to write yaml file, python yaml, what is yaml, what is yaml file, yaml, yaml explained, yaml file, yaml file explained, yaml file tutorial, yaml files, yaml python, yaml tutorial, yaml tutorial for beginners, yaml tutorial in telugu, yml, yml file, yml file tutorial
Id: fwLBfZFrLgI
Channel Id: undefined
Length: 8min 51sec (531 seconds)
Published: Mon Jan 25 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.