Ansible - Understanding YAML with Coding Exercises

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments

Awesome stuff thanks!

👍︎︎ 1 👤︎︎ u/TiminAurora 📅︎︎ Jan 09 2020 🗫︎ replies
Captions
all ansible play books are written in Yammer if you're familiar with gamal already feel free to skip this section and head over to ansible play books in the next section if you have not worked with Yammer in the past I would highly recommend going through this because the rest of the course depends entirely on yamo ansible play books or text files or configuration files rather that are written in a particular format called camel if you have worked with other data structure formats like XML or JSON in the past you should be able to easily pick it up don't worry if you haven't worked on any of this you should still be able to easily pick it up going through the coding exercises accompanying this course a yamo file is used to represent data in this case configuration data here's a quick comparison of a sample data in three different formats the one on the left is XML where we display a list of servers and their information the same data is represented in JSON format in the middle and finally in yellow format to the right so take a minute to go through and compare the three different formats let's take a closer look at llamo if you take data in its simplest form such as key value pair this is how you would define it in yellow key and value separated by a semicolon and a space in this case the keys are fruit vegetable liquid and meat and the values are apple carrot water and chicken remember you must have a space followed by a semicolon differentiating the key and the value let's take a look at how an array is represented we would like to list some fruits and vegetables we would say fruits followed by a semicolon on the next line enter each item with a dash in the front the dash indicates that it's an element of an array how about a dictionary a dictionary is a set of properties grouped together under an item here we try to represent nutrition information of two fruits the calories fat and carbs are different for each fruit notice the blank space between each item you must have equal number of blank spaces before the properties of a single item let's take a closer look at spaces in yellow here we have a dictionary representing the nutrition information of vanilla the total amount of calories fat and carbs are shown notice the number of spaces before each property that indicates these key value pairs fall within banana but what if we had extra spaces for fat and carbs then they fall under calories and does become properties of calories which doesn't make any sense this will also result in a syntax error which will tell you that mapping values are not allowed here because calories already have a value set which is 105 you can either set a direct value or a hashmap you cannot have both so the number of spaces before each property is key in Yammer you must ensure that they are in the right form to represent your data correctly let's take it to another level you can have lists containing dictionaries containing lists in this example I have a list of fruits and the elements of the list are banana and grape but each of these elements are further dictionaries containing nutrition information before we head over to exercises let's take a look at some key notes dictionary is an unordered collection whereas lists are ordered collection so what does that mean the two dictionaries that you see here have the same properties for banana however you can see that the order of properties fat and carbs do not match in the first dictionary fat is defined before carbs and in the second dictionary carbs comes first followed by fat but that doesn't really matter the properties can be defined in any order but the two dictionaries will still be the same as long as the values of each property match this is not the same for lists or arrays arrays are ordered collection so the order of items matter the tool-less shown here are not seen because apple and banana are at different positions this is something to keep in mind while working with data structures also remember any line beginning with a hash is automatically ignored and considered as a comment we are now ready to head over to the coding exercises and have some fun playing with the animal files before heading into exercises let me give you a brief idea on how the exercises the coding exercises work in this course and this is the same way it works for the rest of the course so it's good to have an idea on how to work with the coding exercises so at the end of this video on clicking the continue button you will be automatically taken to the coding exercises section the coding exercises section as you can see it consists of three different parts the area at the top here is where your question is this is where you are given instructions on your task on the left side here you can see two different files you will always see two or more files here the first and the default file is called exercise dot RB this file is never used so you can see a temporary banner put here we never actually use this file if you look at the note here you can see that this file is not used do not type in your solution in this file and you must always use the edges in dot yamo or dot txt file so we will be working with two types of files one is the dot txt file for which we will use for inventory ansible inventory files the other is the dot gamma file which is what we will be working with most of the time and that is the ansible playbook files so never write anything into the exercise RB switch over to the food demo file in this case and if you look at the instructions you can see that the instruction is to update food demo file to add a vegetable carrot so there are currently three types already so create a new entry here called vegetable and enter the name name of the vegetable in this case carrot now if you look at the bottom right corner you will see there are two buttons I click on the check solution button and it will check for your answer and you must ensure that your answer is right in this case I got an error because I typed in the spelling for vegetable wrong so I'm going to correct that click on it again and you should see that your solution is correct so you can then click on the continue button to go over to the second exercise so this way you can go over all exercises until they're complete and if you have any questions about any of these exercises or if you have if you find any issues with any of these exercises feel free to reach out to me click on the Browse Q&A button and then add a new click on the ask a new question button to ask a new question and I will make sure to reply to it as soon as possible so go through the exercises let me know what you think so good luck
Info
Channel: KodeKloud
Views: 53,776
Rating: 4.8207884 out of 5
Keywords: ansible, yaml, training, course, practice, udemy
Id: U9_gfT0n_5Q
Channel Id: undefined
Length: 8min 56sec (536 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.