How Ansible Variables work in a Playbook | Hands-on using Ansible Variables | #Valaxy

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello folks welcome back to Ville axia technologies my name is er Shankar in this lecture we are going to talk about ansible variables in previous lecture we have seen how to convert our cell commands as ansible playbook as a further enhancement to existing playbook will introduce ansible variables which helps us to manage ansible playbooks more efficiently to demonstrate variables we are using same playbook which was written in the previous lecture to install Tomcat server before jumping into over practical session if you haven't subscribed to our YouTube channel please subscribe to it and go through with our previous lecture which talks about how to convert shell commands use ansible playbook addition to this I have created a new dummy course to help you to understand the DevOps project so for nineteen hundred plus people enrolled 322 people given average rating of 4.5 you can check it out if you are interested now come back to our topic there are various ways to pass variables to your ansible playbook it could be defined within the ansible playbook itself parsing from external files passing from hosts inventory or using group where's our host verse if you need more information about this I would request you to go through with the ansible official document to understand more about variables now jump into our ansible server and continue with the same playbook which we used in the previous lecture so I am on my ansible server under Tomcat setup dot yml is the playbook which we have written in the previous lecture to use variables we need to edit this file let me open in the VA mode let's go to starting of the file I mean to say header usually variables you can keep it under worse let me take a first variable value as here Tomcat URL Tomcat URL so what it is I want to specify Tomcat URL here so that I don't need to specify over here whenever I want to change something I will come and change in the header section itself for that I'm copying this URL and keeping it over here now here I no need to use URL itself I will replace this one with my variable name URL our variable name is Tomcat - URL this is our variable rate but whenever you specify variable it must be under flower braces this is how you need to specify variable in case your variable is at the starting of the line then you must keep it under double quotes otherwise it throws young error similar way we can use one more variable that is for under asaji we are using Apache Tomcat and version I don't want to keep it as a hard-coded for that one I'm going to use one more variable I will name it as a tomcat per case I'm just giving it Tomcat package as my variable name I will just specify till here and here I can replace this one with variable star dot G should be there I'm removing this and here my Worrall name is Tomcat package right okay this is my variable name as I said variable if you are specifying it should be in the flower brackets under here we may or may not specify braces why because it is not starting of the line it is in between off your line so no need to mention braces similar way here also we are going to change it with our variable value under spaces it is best practice to mention okay so this is how we can replace our hard-coded values with variables now if I want to change Tomcat packages folder are my URL I can only change over here I have given a space over here so this is how we can use variables now let me save it so let's go to our target system this is our target system so go to Apache Tomcat tube in under this directory we have shutdown dot H is there stop the services and check for services now cesare not running we'll go out under remove this entire folder out of mana saref right we have removed it now let's execute our playbook and Sybil playbook - I host Tomcat set up - - check because I have changed this well let me check oops I have given Tomcat - URL you should not use - or - in the variable name let me change it so we should do underscore instead of - over here so we shall replace the - with undersquare or so this okay it's working and the target system is clean okay anyway file is not there and if you observer you can see here it variable has been replaced with value now without check mix routing so let it run meantime if I check this it is not working okay downloaded yes extracted as well yes service is also running and let's access our Tomcat server right this is how we can use variables in the ansible playbook but you don't want to use variables within the ansible playbook you can use ansible variables in a different different formats even we can specify variables outside of our playbook as well assume that let's create a tomcat undersquare verse I will keep these two variables over here right so I will just mention these variables over here the file now in PlayBook instead of specifying variables over here I will remove this one and replace this as a verse under square files and I can specify the file name what is our file name - Tomcat underscore of ours right now also it will do the same thing Tomcat underscore sorry Tomcat set up under Tomcat underscore verse now let's do the installation one more time before that let's stop it Apache Tomcat Apache Tomcat been shut down that Sh I have dropped atomic our services yes now remove the Apache packages nothing is there this time I'm going to execute playbook one more time before executing I will check it out No let's execute actually and it calls variables from the Tomcat where's learn to replace the values let's see it's downloading all right it has done under this term also if we see Tomcat is there and services if I check it's running and again I can able to access my website right this is how we can use variables within the ansible playbook under calling externally from variables fell apart from these we have group where's host words and a few other ways we can call variables depends upon where you are calling the priority get changes we'll see how group works and host works works well using rules right that's all for this lecture hope you got a basic idea of variables there is lot you can do with variables but I will teach what is the best of practice and how we use variables in the real world when we are talking about roles thanks for watching this video in next video we are going to see notify under handlers thank you if you haven't subscribed yet please subscribe to our Channel see you in the next video
Info
Channel: Valaxy Technologies
Views: 40,898
Rating: undefined out of 5
Keywords: aws, devops, valaxy technologies, security, automation, ansible, ansible valaxy, ar shankar ansible, valaxy ar shankar devops, ar shankar devops, ansible variables, valaxy ansible, what is ansible variables, how to use ansible variables, how to define varialbes in a playbook, how to call varialbes file from ansible playbook, introduction to ansible variables, using ansible varaibles, valaxy devops, valaxy technologies devops, ansible palybook with variables
Id: 1VRsp2tGQjE
Channel Id: undefined
Length: 10min 22sec (622 seconds)
Published: Wed Nov 06 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.