Ansible Full Course | Zero to Hero — Transcript
Full transcript
- 0:00hello there and welcome to this anible
- 0:02course this is Rahul and before we jump
- 0:04into our anible course let's take a
- 0:06pause over here and take a look onto the
- 0:08topics which we are going to cover into
- 0:09this particular Series so here I have
- 0:12listed all the topic and I will also
- 0:14leave the time stamp of each chapter
- 0:16into the description section so if
- 0:18you're just uh getting started with the
- 0:20anible then I would highly recommend to
- 0:22go through all this chapter and for
- 0:24those who are already familiar with
- 0:26these kind of a concept then just check
- 0:28the Tim stamp and look for the spefic
- 0:30specific chapter uh which you want to
- 0:31practice or which you want to learn and
- 0:33the last chapter of this inable series
- 0:35I'm just going to cover one project
- 0:37where I have written my own anible
- 0:39Playbook to deploy my own blog so this
- 0:42Playbook will help you to understand how
- 0:44you can use your concept to create your
- 0:46own anible automation so don't miss that
- 0:49chapter if you want to really learn like
- 0:51how the anible work in real time so
- 0:54without further Ado let's start with our
- 0:55chapter
- 0:57one now back to the important questions
- 1:00like what the anible is so anible is an
- 1:02open- Source tool which help you majorly
- 1:04with the three tasks so the first task
- 1:06is uh the software installation so with
- 1:09the help of anible you can automate the
- 1:11task of installing software onto various
- 1:14servers second it can help you to manage
- 1:17the server configuration and what does
- 1:19it mean so with the help of management
- 1:21of a server configuration you can add a
- 1:23new configuration you can update a uh
- 1:26any existing configuration and even you
- 1:28can delete the uh configuration ation of
- 1:30a server the third thing and which is
- 1:32the most important thing is you can
- 1:34deploy your web application or any kind
- 1:36of application on a server and you can
- 1:39even automate that task using the anible
- 1:42All right so I don't want to stuff you
- 1:44with a lot of theory about anible and
- 1:46why don't we switch to our desktop and
- 1:48see a very small Playbook where we will
- 1:51try to see like how we can automate the
- 1:53installation of a software packages
- 1:55using the anible and also we will see if
- 1:57we don't have an anible then how we are
- 1:59going to install a software package on a
- 2:02server so that you can get the
- 2:04understanding like if you have a anible
- 2:06then how you will automate the task and
- 2:08if you don't have the anible then how
- 2:10you're going to handle those task so
- 2:12let's switch over to my desktop and see
- 2:13that small anible Playbook all right
- 2:16let's try to understand the scenario
- 2:17where you don't have a anible with you
- 2:20so how you're going to install the
- 2:21software packages so here onto the
- 2:23screen if you will see on the left hand
- 2:25side I have some script which is like
- 2:28installing uh python and creating a
- 2:31directory and also installing an Apache
- 2:332 server and on the right hand side if
- 2:35you'll see this is my remote server with
- 2:37an external IP which I have highlighted
- 2:40in the red color font so that's the
- 2:42remote server where I'm just going to
- 2:43execute this command and since I don't
- 2:46have an anible with me so what I'm going
- 2:48to do I'm just going to use the simple
- 2:49SSH method to login into the server and
- 2:52execute these commands so that I can
- 2:54install python I can install Apache 2
- 2:57and also I can create the directory so
- 2:59this this is the way I'm just going to
- 3:01do if I don't have the anible the next
- 3:03thing which I'm just going to show a
- 3:05glimpse of a anible Playbook where we
- 3:07are just going to automate all this task
- 3:09into a single Playbook which is we call
- 3:12it as a anible Playbook all right moving
- 3:14to the anible part so this is the
- 3:16smallest sensible Playbook which I have
- 3:18for this uh particular very short demo
- 3:21so I'll start from the top over here so
- 3:23here you can see uh this is the first
- 3:25task which I have written over here for
- 3:27installing the python so here uh one
- 3:30disclaimer I would like to give you here
- 3:32this is a introductory part here I'm
- 3:34just trying to explain the difference
- 3:36between if you don't use anible and when
- 3:38you use anible so don't try to uh like
- 3:41remember everything over here because we
- 3:44will take a deep dive look into the each
- 3:46file inventory task and the playbooks
- 3:49into the letter session and also we will
- 3:51take a look on how to install the anible
- 3:53also so we will start from that
- 3:55particular uh stage where we don't have
- 3:57the anible installed onto over system
- 4:00here I'm just trying to explain the
- 4:02difference between when you don't have a
- 4:03anible and when you have a anible so
- 4:05what are the changes you will see okay
- 4:08so now coming back over here so this is
- 4:10the first task which I have written into
- 4:12my anible playbook which which will
- 4:14install the python onto my uh remote
- 4:17server second this is the task for
- 4:20creating the directory this is the third
- 4:23task for installing the Apache 2 server
- 4:25so here you will see the differences so
- 4:28if you go back to our present ation deck
- 4:30where I have shown you so here you will
- 4:31see the oneliner commands so these
- 4:34oneliner commands are not
- 4:35self-explanatory unless and until you
- 4:37know or you have used those command in
- 4:39the past so here you will see although
- 4:42it is really short and although you can
- 4:44uh combine all these commands into a
- 4:46single shell script file but it doesn't
- 4:49look so intutive if any other developer
- 4:52is working on to this bash script then
- 4:55he will find a little bit of difficulty
- 4:57understanding uh those command because
- 4:59those are not so much they don't have
- 5:01the description behind them but if you
- 5:04take a look over here into the anible
- 5:06Playbook so here this is the first task
- 5:08here you have the name this name is
- 5:10really self-explanatory like what it is
- 5:12trying to do here is the second task
- 5:15where I'm also writing my own custom
- 5:17name like create directory I can explain
- 5:20further more like what kind of a
- 5:21directory I want to create and here is
- 5:23the third task where I'm just saying uh
- 5:26explicitly hey I'm trying to install the
- 5:28python so this is the main difference
- 5:30between the uh when you don't use anible
- 5:33and when you use anible all right so
- 5:35let's SSH into the server which is
- 5:37running remotely and this is my terminal
- 5:40over here if you can see and the command
- 5:42which I'm just going to run is this one
- 5:44so this is my SSH command and this is
- 5:46the private key I'm using to SSH uh in
- 5:49case if you are having a remote machine
- 5:51and you have a username and password
- 5:53then you can use the puty also since I'm
- 5:56using the Mac machine that's why I'm
- 5:57using the SSH command but in case if you
- 5:59if you're using the Windows machine then
- 6:01you can uh use the putty utility where
- 6:03you can just specify the external IP
- 6:06your username and password and in case
- 6:08if you're having a private key then you
- 6:10can just simply add your private key
- 6:12over here followed by the username and
- 6:15the external IP so this is the way you
- 6:17can do the SSH into your remote machine
- 6:19but anyways so this is the way I'm just
- 6:22going to do the SSH into my uh remote
- 6:24machine and this IP is little bit
- 6:25different from my initial uh PP which I
- 6:28have shown to you because I have started
- 6:29a new virtual machine that's why I have
- 6:31got the new IP so I'm just going to
- 6:34execute this
- 6:35command and here you can see I'm able to
- 6:37SSH into my remote server all right now
- 6:41the next thing which we are going to do
- 6:42we are just going to run those command
- 6:44manually without using anible so that we
- 6:47can analyze like what's the difference
- 6:49uh we observe between the without using
- 6:52anible and with using anible so uh this
- 6:55is the bash script uh which I have
- 6:57written over here so I'm just going to
- 6:58manually run one by one command onto my
- 7:01terminal so the first thing which I'm
- 7:02just going to do I'm just going to do
- 7:04the appt gate update which is uh for
- 7:06updating the package manager of my Linux
- 7:09machine since I'm using devian base UB 2
- 7:12that's why I'm using the app uh package
- 7:14manager so I'm just going to paste the
- 7:16command over here and this is the way we
- 7:19are just going to update the package
- 7:20manager I'm just going to speed up some
- 7:22of the
- 7:25commands so First Command has been
- 7:28executed the next command which I'm just
- 7:29is going to run is the install python so
- 7:32I'm just going to open the terminal once
- 7:33again I'm just going to paste it over
- 7:35here so here I just wanted to show you
- 7:38uh like if you don't use the anable then
- 7:40this is how you are just going to set up
- 7:42your server where you're just trying to
- 7:44install one package uh one after another
- 7:46so here you can see the python version
- 7:48is already by default installed so it is
- 7:50not going to install the
- 7:52python moving further so here I'm just
- 7:54going to create the directory so this is
- 7:56the command uh I'm just going to paste
- 7:58it over here and here I'm just going to
- 8:02run the ls command and here you can see
- 8:03this is the basic HTTP directory which
- 8:05has which has been
- 8:07created all right the next thing which
- 8:09I'm just going to do I'm just going to
- 8:10copy the installation command for Apache
- 8:13server I'm just going to head over to my
- 8:16terminal over here I'm just going to
- 8:17paste the
- 8:19command all right so here you can see we
- 8:21have installed the Apache server now
- 8:24what we need to do is we need to enable
- 8:25the Apache so this is the command which
- 8:27I'm just going to use so again I'm just
- 8:28going to go to ter I'm just going to
- 8:30paste the command and hit
- 8:32enter and here you can see we have
- 8:34started our Apache 2 server the next
- 8:37thing which we're going to do we're just
- 8:38going to verify the status of a PES so
- 8:40I'm just going to run system
- 8:43CTL
- 8:48[Music]
- 8:51uh and here you can see uh the status of
- 8:54Apache to server service is green that
- 8:56means we have successfully installed the
- 8:58Apache to server on to our Linux machine
- 9:01okay so now you have seen the manual way
- 9:03when we don't have the anible with me
- 9:05then this is the way I'm just going to
- 9:07install the software packages onto my
- 9:09remote server now I'm just going to
- 9:11switch over to the anible way where I'm
- 9:13just going to run only single Playbook
- 9:15and that will install all these packages
- 9:18using the anible All right so now we
- 9:20have seen the manual way of installing
- 9:22the software packages using the bash
- 9:24script but now let's uh take a look onto
- 9:26the Playbook once again so this is the
- 9:28Playbook which have explained to you
- 9:30earlier and the name of the Playbook
- 9:32which I will be using for running this
- 9:34Playbook is VM setup playay book. yml
- 9:37this font might be small but uh when
- 9:39I'll switch over to terminal then I can
- 9:40show you the exact name okay so I'm just
- 9:43going to switch to my terminal and this
- 9:45is the command which I'm just going to
- 9:46run so that starts with the keyword
- 9:48anible Playbook after that you need to
- 9:51specify the remote host uh which we call
- 9:54it as a inventory in anible we will take
- 9:56a look uh uh in the letter session for
- 9:59the inventory and the host but just to
- 10:01keep you uh just to give you a little
- 10:03bit brief so this is the name of the
- 10:05host file actually that means the remote
- 10:08machine and this is the name of the
- 10:10Playbook which I was referring to I can
- 10:12show you the host file where I have made
- 10:13an entry for our remote machine so if
- 10:17you go over here so this is the host and
- 10:19this is the IP address of my remote
- 10:21machine or the remote server so this is
- 10:24how uh the basic and simple play look
- 10:26like so this is the command which I'm
- 10:28just going to execute and you just
- 10:29simply need to hit
- 10:31enter and if this is the first time you
- 10:33are connecting to your remote server
- 10:35then it is going to ask are you sure you
- 10:36you want to connect you simply need to
- 10:38type yes and hit enter and then it will
- 10:41take maybe couple of minute or 3 minute
- 10:43to complete the Playbook but uh
- 10:45meanwhile I can show you some of the
- 10:47output which it generate to tell you
- 10:50that what task it has finished so here
- 10:52you can see it is installing the
- 10:56python and here you can see uh the
- 10:59status change that means it has
- 11:01installed the python the next task which
- 11:03it is doing it is creating a directory
- 11:06and the third task which it is doing is
- 11:08to install the Apache and as soon as all
- 11:11the three task has been finished and you
- 11:13will see a su a message over here that
- 11:16like three changed okay for and you will
- 11:19not see any error message that means
- 11:21your anible playbook has successfully
- 11:23finished and now we can SSH into server
- 11:26and verify that it has installed the
- 11:28required packages which we have
- 11:30mentioned inside our anible Playbook
- 11:32okay so I'm I have opened one another
- 11:34terminal and here I have mentioned the
- 11:36SSH command and the remote IP of my
- 11:39remote server I'm just going to Simply
- 11:41hit enter and here I'm into my remote
- 11:43machine and here we can verify one by
- 11:45one so first of all I'm just going to
- 11:47run the ls command to verify the
- 11:48directory and here you can see this
- 11:50directory has been created the first
- 11:53thing uh which I forgot to check is the
- 11:55python command so I'm just going to run
- 11:57the command Python 3 version and here
- 12:01you can see python has been installed
- 12:03the third thing which I need to verify
- 12:04is the Apache 2 server so I'm just going
- 12:06to run the system CTL
- 12:10status and Apache 2 and here you can see
- 12:15it has uh installed the Apache 2 also so
- 12:18that means our anible Playbook has
- 12:20finished the task and it has
- 12:22successfully install all the three
- 12:24things which we have asked all right so
- 12:26now we have taken a look onto the very
- 12:28small demo of anible and I really felt
- 12:30that demo is really essential for you to
- 12:33understand the anible better now in the
- 12:35next session we will take a look like
- 12:37why anible is called agentless and also
- 12:40we are going to take a look like how to
- 12:41install anible onto your local machine
- 12:44so that you can uh run the anible
- 12:46Playbook and you can just make a
- 12:48software installation change config and
- 12:50deploy your web application so those we
- 12:53are those are the topics which we are
- 12:54going to cover into the next
- 12:57session welcome to the second part of
- 12:59the anible series and in this session we
- 13:01are going to take a look like why anible
- 13:04is called agentless and later we are
- 13:06going to take a look how to install
- 13:07anible onto your local development
- 13:09machine so that you can develop your own
- 13:11anible Playbook coming back to the
- 13:13question like why an is called agentless
- 13:16to answer that question here I have
- 13:18prepared a diagram and onto the left
- 13:20hand side you will see a developer uh
- 13:22with his or her laptop or working laptop
- 13:25where he has or she has installed anible
- 13:29and on the right hand side you will see
- 13:30the remote servers uh it can be on
- 13:33premise remote server it can be uh
- 13:35hosted on a Google Cloud platform or AWS
- 13:38or any other cloud provider but that REM
- 13:41uh server has to be remote okay so now
- 13:44uh there is anible and that anible we
- 13:46have installed onto the developer
- 13:48machines not onto the servers so pay
- 13:52attention carefully we have installed
- 13:54anible on a developer machine so if I'm
- 13:56working on my playbook then I have
- 13:58installed nible on my local development
- 14:00machine so I will prepare my uh ncble
- 14:04Playbook I will write some instructions
- 14:06inside my ncble playbook and I I will
- 14:09run the ncble Playbook command and as
- 14:11soon as I run the ncble Playbook command
- 14:13it will connect to those servers using
- 14:16SSH it is same as when you try to log to
- 14:19your remote server using SSH so it will
- 14:21use the SSH it will connect to those
- 14:23server and it will execute all the
- 14:26required command which is necessary or
- 14:28which we have a speci classified into
- 14:30our playbooks so this is why the anible
- 14:33is called agentless all right so now we
- 14:35know that anible is agentless now the
- 14:38next question comes like how can I write
- 14:40the anible Playbook and what's the
- 14:42extension uh in which I should save the
- 14:45anible Playbook so as you can see onto
- 14:47the diagram onto the left hand side so
- 14:49you need to save your anible playbook
- 14:51with the extension. yml so yml extension
- 14:55is used for anible Playbook and you have
- 14:57to follow the yml conventions to write
- 15:00your anible instructions inside your
- 15:02anible playbook and here you can see I
- 15:04have taken a very basic uh code snippet
- 15:07screenshot where I have created uh like
- 15:10anible instruction for installing the
- 15:12Apache server so this file I'm just
- 15:14going to save with the yml extension and
- 15:16then I'm just going to execute the N
- 15:18Playbook command to uh run it on a
- 15:20different different server so this is
- 15:22the uh diagram which I just wanted to
- 15:24show you like how you're going to create
- 15:26and save your uh ncble Playbook with the
- 15:29yml extension now the next thing which
- 15:30you need to do you need to install the
- 15:32anible based on the operating system
- 15:34which you are using so first I will
- 15:37start with the windows and as you know
- 15:39from the Windows 10 and windows 11 we
- 15:41have the capability to run the Linux uh
- 15:43operating system inside your Windows
- 15:45machine so for that we will be using WSL
- 15:49uh utility provided by our Windows to
- 15:51install the ubun 2 or a Santos based
- 15:53operating system inside your Windows
- 15:56machine because uh it is really easy to
- 15:58run the anible in inside your Linux
- 16:01machine so for that purpose we are going
- 16:03to use the WSL utility for Windows here
- 16:06onto the screen you can see there is a
- 16:08really good documentation from a
- 16:09canonical entu community and this is the
- 16:12official page of the canonical entu
- 16:14where they have shown like how to set up
- 16:16your WSL on a Windows 10 as well as
- 16:19Windows 11 machines so here first of all
- 16:22you need to uh install the WSL utility
- 16:25so this particular section or these two
- 16:27links actually uh this is for Windows 10
- 16:31and this link is for Windows 10 as well
- 16:33as the windows 11 so I'll put both of
- 16:36the link into the description section of
- 16:38the video so if you are using the
- 16:39windows then I would highly recommend to
- 16:41follow these uh instruction which is
- 16:44mentioned on uban 2 canonical okay so
- 16:47let's go through it so this is the
- 16:48overview like uh what you need to do uh
- 16:51second if you click on the WSL then they
- 16:53have taken a really good screenshots
- 16:55like how to proceed forward so here uh
- 16:58you first go need to go to the Microsoft
- 17:00store where you need to look for a
- 17:01Windows subsystem and after that you
- 17:04need to install that thing and once you
- 17:07install the windows subsystem then you
- 17:09will get this terminal and there you
- 17:11need to install the Ubuntu so here after
- 17:14that you need to uh download the uban 2
- 17:17and here you need to mention like uh
- 17:19what version you need to install for the
- 17:21uban 2 I would recommend choose uh the
- 17:24long-term uh LTS based UB 2 version
- 17:27system because uh canonical has a really
- 17:30good support for LTS version so I would
- 17:32recommend to choose the latest and LTS
- 17:34version of Uub 2 so here you can
- 17:37download the uban 2 and once you have
- 17:39downloaded the uban 2 then you can uh go
- 17:41to this start screen select the uban 2
- 17:44and the maybe the next step would be the
- 17:46configure UB 2 and here you will see the
- 17:49terminal where you can just log to your
- 17:52UB 2 machine uh so that you just need to
- 17:54provide the username and the
- 17:56password and after that once you have
- 17:58installed the ubu then the First Command
- 18:00which you need to run is the Pudo appt
- 18:02update onto the terminal so that it can
- 18:05update its packages and at last you can
- 18:07install and use the GUI packages uh
- 18:10which is provided by a WSL for your ubu
- 18:13so that you can use the graphical
- 18:14interface uh for your UB 2 machine so
- 18:17just follow these instructions and uh uh
- 18:20set up your WSL uh based on the Windows
- 18:2310 or Windows 11 operating system and
- 18:26once you have a WSL and ubun 2 setup on
- 18:28your Windows machine then you can simply
- 18:31jump uh to the next instruction uh like
- 18:34uh the second and the third operating
- 18:36system like Ubuntu or Santo so here I'm
- 18:39assuming that on your Windows machine
- 18:41you are using Ubuntu so you can just
- 18:44follow the Pudo app to get install
- 18:46anible command which I'll I'll show you
- 18:48onto my one to machine uh that how to
- 18:51install the anible so you can just
- 18:52simply follow those instructions to
- 18:54install uh anible because on Windows
- 18:57machine you are running to then you just
- 18:59need to copy these instructions over
- 19:01there and you can uh just get yourself
- 19:04started with the so here is my terminal
- 19:06and this is my Ubuntu machine so first
- 19:08of all let's verify the version of my
- 19:10Ubuntu Machine by running this command
- 19:12so here you can see this is the Debian
- 19:14based uh operating system so deian based
- 19:16also like Ubuntu is a Debian based
- 19:18operating system so all the command
- 19:21which I'm running over here will be uh
- 19:23applicable for any Ubuntu machine so if
- 19:26you are using Ubuntu on your Windows
- 19:27machine then you can simply run these
- 19:29commands to install the nle so the First
- 19:32Command which I'm just going to run I'll
- 19:34first of all clear the screen is Pudo
- 19:36app gate update so this is the first
- 19:38command I would recommend you to run so
- 19:40that it can update all the uh apt
- 19:42packages all right so that has been done
- 19:45successfully the next command which I'm
- 19:47just going to run is to in install the
- 19:49anible uh repository but before that I'm
- 19:52just going to run this uh install
- 19:54software properties common command type
- 19:58yes it will install it okay that's been
- 20:00done I'll clear the screen now I'm just
- 20:02going to install the repository from
- 20:04where we are just going to fetch the an
- 20:06so this is the command for installing or
- 20:09installing the anible repository onto my
- 20:11Ubuntu machine so I'm just going to
- 20:13Simply hit enter and just going to press
- 20:15enter and here we have downloaded the
- 20:17repository for anible and the next
- 20:19command which I'm just going to run is
- 20:21the Pudo epate update once again because
- 20:24we have just recently added the uh
- 20:26anible repository so this is the command
- 20:28to update the uh repository definitions
- 20:31over here and here we can see our anible
- 20:35repository has been
- 20:37updated okay I'll clear the screen and
- 20:40the final command which I'm just going
- 20:41to run is the Pudo apate update install
- 20:45anible and hit enter type yes all right
- 20:49so here you can see our anible
- 20:51installation has been finished so I'm
- 20:52just going to clear the screen and I'm
- 20:54just going to run the
- 20:55anible version command to verify by the
- 21:00version uh I would say I'll C the screen
- 21:02once more I need to add one more Dash
- 21:05over here to get the correct version and
- 21:08here you can see this is the version uh
- 21:10Nal 2.10 which we have installed onto
- 21:12our2 machine I'll put all this command
- 21:15into the description section uh so that
- 21:17you can follow this command to install
- 21:19the uh anible onto your ub2 system the
- 21:23next uh we are going to do we are just
- 21:25going to install the anible onto the
- 21:27sent OS the Y uh package manager okay so
- 21:30the next uh installation which we are
- 21:32going to do we are just going to install
- 21:34onto our Santo operating system so we
- 21:36have covered the windows we have covered
- 21:38the UB to the next thing which we are
- 21:39going to do we are going to install the
- 21:41anible onto the sent OS so this is the
- 21:44terminal of my Centos machine I'm just
- 21:46going to minimize this thing so this is
- 21:48the terminal from my sent OS machine so
- 21:51first of all let's verify the santoos
- 21:53version and the command for that is cat
- 21:55Etc santoos release and it will let you
- 21:58know the version so here I'm using the
- 21:59Santos release 8 version so that we have
- 22:03verified the next thing which we are
- 22:04going to do we are just going to run the
- 22:06Yum update command so that uh uh we
- 22:09update all the package manager so the
- 22:12command is sudo uh yum
- 22:15update okay so now we have finished the
- 22:17Yum update command so I'm just going to
- 22:19clear the screen the next command which
- 22:20I'm just going to run is the Pudo uh
- 22:22sorry yum install eepl release and I'm
- 22:25just going to add Pudo over here
- 22:29so this will basically install the EPL
- 22:32release package and after that we will
- 22:34be able to install the anible onto our
- 22:36Santo
- 22:37machine type
- 22:39yes and here we have uh successfully
- 22:42installed the EPL release package and
- 22:44the next command which I'm just going to
- 22:46run is the I'm just going to clear the
- 22:48screen first of all sud sudo yum install
- 22:52anible all right so now the anible uh y
- 22:54install anible command has just finished
- 22:56I'm just going to clear the screen and
- 22:58I'm just going to verify the anible
- 23:00installation by running the command
- 23:02anible version and here you can see uh
- 23:05we have installed the anible 2.3.5 onto
- 23:08our Santo system the next thing which we
- 23:11are going to try out is we are just
- 23:12going to install uh anible onto our Mac
- 23:15OS if you are using the Mac OS then
- 23:18installation of a anible on a Mac OS is
- 23:21pretty simple uh you just need to rely
- 23:23on the Brew package manager and the
- 23:25command for installing the anible is the
- 23:27Brew install anel and that should take
- 23:30care of the anible installation onto
- 23:32your Mac OS so here you can see I have
- 23:35already installed anible that's why it
- 23:37is showing me that anel has already
- 23:39installed but in case if you don't have
- 23:41anel installed onto your Mac operating
- 23:43system then you just simply need to
- 23:45execute PR install anible and that will
- 23:47take care of the anible installation now
- 23:50after installing the anible the next lap
- 23:52session we are going to discuss more
- 23:54about the anible project setup so here I
- 23:56have taken a very brief screenshot where
- 23:59I have shown a project structure of my
- 24:01anible project so where I have shown
- 24:03like how I have created the inventory
- 24:05file uh where is my host file what are
- 24:07the roles I need to create inside my
- 24:09anible playbook uh what does it mean by
- 24:12the task uh and how should I set up my
- 24:14anible uh Playbook yml so this is the
- 24:17project setup we will take a deep dive
- 24:19into for our next
- 24:23session welcome back and till now so far
- 24:26we have seen like what the is and how to
- 24:29do the Nel installation but in this lab
- 24:32session we are going to take a look onto
- 24:33the project structure of our Nel so here
- 24:36we will talk about the inventory file we
- 24:38will talk about the task and our main
- 24:40Playbook and how to execute it so here
- 24:43you can see onto the screen this is the
- 24:45typical project structure of my anible
- 24:47so here we are talking about the
- 24:49inventory roles and my main Playbook
- 24:51file but don't worry we are going to
- 24:53take a look onto the each uh file which
- 24:56is present inside our project structure
- 24:58moving to the next slide so here you
- 24:59will see a remote server with a
- 25:01dedicated IP so I'm just assuming that
- 25:04this is going to be my dedicated server
- 25:06and for This Server I'm just going to
- 25:08write my anible playbook so first of all
- 25:12in this slide you will see on the right
- 25:13hand side my dedicated server which is a
- 25:16remote server present somewhere and
- 25:18after that you will on the left hand
- 25:19side you will see this is the typical
- 25:21project structure of my anel so we'll
- 25:24start from the host file so if you'll
- 25:26see uh whenever you work with anible
- 25:28then you need to create the host file
- 25:30and inside that host file you need to
- 25:32mention the either IP address or the
- 25:35domain name of our particular remote
- 25:37machine so here you can see this is the
- 25:39uh IP address which I have written it
- 25:41over here inside my host file so that
- 25:44anible knows like which host it can
- 25:47connect so here this is a single server
- 25:49I have used inside my anible playbook so
- 25:52that's why I'm using the single IP over
- 25:54here but in case if you are having a
- 25:56multiple server then you can create a
- 25:57multi mle entries inside this host file
- 26:01so this is how it works so here you will
- 26:03have a host file in your project inside
- 26:06the inventory directory and inside that
- 26:08inventory directory you can create a
- 26:09multiple host file also that's
- 26:12absolutely okay so I'm just taking one
- 26:14example uh for Server remote server so
- 26:16that's why I have only one host file and
- 26:19this host file contains the IP address
- 26:21and this IP address will point to our
- 26:23remote machine so that's the first uh
- 26:26basic file which we need for creating
- 26:29our anible Playbook and that is our host
- 26:31file all right moving to the next file
- 26:33where we will be talking about the roles
- 26:35and the task associated with particular
- 26:37role so here onto the screen if you'll
- 26:40see this is the main. yml which is a
- 26:42task present inside a role and the role
- 26:45name is python so pay attention
- 26:47carefully over here for anible Playbook
- 26:50you can have a multiple role and each
- 26:52role can have a task so here I have
- 26:55created a role that is Python and inside
- 26:57that pyth python we have a task and that
- 27:00task we have defined inside our main.
- 27:02yml and what's the purpose of that
- 27:05particular task so in this task we we
- 27:08are trying to execute uh the python
- 27:11installation and after that we are just
- 27:12trying to create a directory and then
- 27:15after that we just trying to install the
- 27:16Apache so this task basically contains
- 27:19the three uh instruction which we need
- 27:22to uh perform onto our remote machine
- 27:24using anel so once we execute this
- 27:27anible plate book then this particular
- 27:30task that is python task will be
- 27:32executed and once it is executed then
- 27:34these three instructions will be pass to
- 27:36the server using our anel so that's the
- 27:39purpose of our roles and the task inside
- 27:42our anel all right so now the final
- 27:44piece inside our anible project is our
- 27:47anible Playbook so if you look onto the
- 27:49screen so this is the name of my
- 27:51playbook so the Playbook name is VM
- 27:53setup playay book. yml you can keep any
- 27:56name of your choice for your anible
- 27:58Playbook that's absolutely okay now
- 28:01since we have talked about uh task as
- 28:03well as our host file so we need to
- 28:05include both the host as well as the
- 28:08task inside our anible Playbook so if
- 28:10you'll see over here so this is my uh VM
- 28:13setup Playbook yml that is a my playbook
- 28:16for anible and in this file you will see
- 28:19two thing so at the line number three
- 28:21you will find host that means what host
- 28:24it is going to connect so here I have
- 28:26specified all so that means it is going
- 28:28to execute this Playbook on all the host
- 28:31which I have defined inside my host file
- 28:34so here in my host file I only defined
- 28:36one remote server so this Playbook will
- 28:39run on that particular remote machine so
- 28:42if you have more than one host inside my
- 28:45host file then this Playbook will run on
- 28:47all those host machine so that's why the
- 28:49host all we have defined over here the
- 28:52next thing we need to Define is the
- 28:54remote user so whenever you try to
- 28:56connect to any remote machine using SSH
- 28:59then you need to have a username so here
- 29:01we need to define the username what will
- 29:03be the remote user so here I'm using
- 29:05Ubuntu as my remote user for that
- 29:08particular machine and this might differ
- 29:10because if you're working on anible
- 29:12Project then you might have uh remote
- 29:15server access with your own username so
- 29:17you need to use your own username
- 29:19instead of Ubuntu over here so that's
- 29:21the purpose of the remote user the third
- 29:24thing which you will see over here into
- 29:26this Playbook is the roles so here here
- 29:28uh the the second uh picture if you'll
- 29:30see over here so where we have defined
- 29:32the main. yml and where we have defined
- 29:34the different different tasks so this is
- 29:37the role which we need to include and
- 29:38that is Python and if you that python
- 29:41role is available inside our project
- 29:43screenshot where you can see roles
- 29:45Python and task so here we have included
- 29:48the python role so this is how this
- 29:50complete anible works and how you put
- 29:53host as well as your roles and task as
- 29:56well as uh your own user if you're are
- 29:59having your own user assigned to that
- 30:01remote machine so you need to put the
- 30:03usern name onto your anible playb all
- 30:06right so now you know like how the N
- 30:08project looks like and what is your host
- 30:10inventory roles and task now what's the
- 30:13command for executing this whole project
- 30:15so here onto the screen you will see the
- 30:17anible Playbook command which I have
- 30:19mentioned for this particular project
- 30:21and this anible uh Playbook command I
- 30:24have break I have broke into three parts
- 30:26so first part is the anible Playbook
- 30:28that's the actual keyword which we need
- 30:30to use after installing the N second we
- 30:33need to specify like which host on which
- 30:36we want to run so here we have a
- 30:38specified inventory and then inside that
- 30:40inventory we need to specify the exact
- 30:43path of our host file so that host file
- 30:45is present under inventory VM setup
- 30:48Playbook and host that's the name of my
- 30:50host file so you need to carefully
- 30:53assign the host name or the host path
- 30:55over here the third thing is is the
- 30:58actual Playbook name so that's my actual
- 31:00Playbook which I have created which
- 31:02consist of roles uh remote user and the
- 31:05host file on which host we want to
- 31:08execute actually so this is the anible
- 31:10Playbook command which you need to run
- 31:13to execute this whole project all right
- 31:16so now you have a little bit of fair
- 31:18understanding on the anible project
- 31:19structure now we will take a deep dive
- 31:22into the each individual file which I
- 31:24have just explained to you so here onto
- 31:26the screen the first file which are
- 31:28which we are going to see over here is
- 31:30the VM setup Playbook yml so here first
- 31:33of all we need to specify the name of
- 31:35the Playbook uh that's something a
- 31:37description which you can put second
- 31:39here we need to specify the host so that
- 31:42I have specified as all so let's take a
- 31:45look onto the host file first of all so
- 31:47here onto this project you will find a
- 31:50host file which I have created and
- 31:52inside that host file I have created a
- 31:54suitable name like gcp host because that
- 31:56virtual machine is on to Google Cloud
- 31:59but that's something I will explain it
- 32:01later like how to set up the Google
- 32:03cloud or AWS but that's something for
- 32:06later sessions but here uh I have
- 32:09specified the IP address and uh this is
- 32:11the uh private key which I will be using
- 32:14to connect to that particular machine
- 32:16but I have a next chapter for this SSH
- 32:18private key and public key setup with
- 32:20the anible but the key thing over here
- 32:23is this particular IP address so that's
- 32:26the remote machine IP address which I
- 32:28will be needing or this anible Playbook
- 32:30will be needing so that's why uh this uh
- 32:33uh this Playbook contains the host all
- 32:35so that means all the host inside this
- 32:38particular uh this particular host file
- 32:40so here I have only one if in case I
- 32:42have more than uh one or two then I can
- 32:45execute the Playbook on all those host
- 32:48that's the purpose of that all inside
- 32:50that particular and civil Playbook okay
- 32:52moving back to the Playbook once again
- 32:54so now we have seen the name we have
- 32:56seen the host now we need to look onto
- 32:59the remote user so as you remember
- 33:02whenever you connect to the remote
- 33:04machine then you need to have a remote
- 33:06user so here the remote user is rul p so
- 33:10that's the user which exist onto that
- 33:12remote machine I'll I'll show you all
- 33:15right so this is my terminal and I'm
- 33:16just going to SSH into this machine
- 33:18using the username Rahul V so I'm just
- 33:21going to paste the command over here so
- 33:23if you'll see this is the SSH and this
- 33:25is my host uh this is my priv private
- 33:28SSH key and this is the username and the
- 33:31IP address of my machine and in case if
- 33:33you're are not using the private key
- 33:35then you can simply use the username and
- 33:37the password assigned to you so here I'm
- 33:40just using private uh and the public key
- 33:42that's why I don't need to assign my
- 33:44username and password but this just an
- 33:47example uh if you have a username and
- 33:49password then it's absolutely okay to
- 33:51SSH using the username and password and
- 33:53you can just simply enter type yes to
- 33:56accept it and here you can see uh I just
- 33:59logged in into my machine and the
- 34:01username is Rahul V because that's the
- 34:04user I have created on that Linux
- 34:06machine so I just wanted to show you
- 34:08because uh if you go to this ncble
- 34:11Playbook once again so that's why I have
- 34:13used the remote user over here as Rahul
- 34:16V so you need to know like what kind of
- 34:18a user you want to become over there and
- 34:21if you want to execute with the root
- 34:22then you can mention the root also over
- 34:25here that's absolutely fine with the
- 34:26anible now the last last thing which is
- 34:28left inside this Playbook is the roles
- 34:30and roles I'm using over here is python
- 34:33so here you if you take a look onto this
- 34:35rules directory I'll just close it and I
- 34:37reopen it so here we are having a roles
- 34:39and inside that role we have defined the
- 34:41role as Python and in that inside that
- 34:44python Ro we have a task and that task
- 34:46contains main. yml so if you open that
- 34:49main. yml then you will find the uh
- 34:51instruction which we need to execute
- 34:53onto that remote machine so here I'm
- 34:55installing Python and I'm just creating
- 34:58One Directory over here and then I'm
- 35:00finally I'm installing the apach so
- 35:03that's the task definition or the test
- 35:05task configuration of our anible looks
- 35:08like so these instructions going to
- 35:09execute onto our anible Playbook now the
- 35:12next thing which I'm just going to do
- 35:13I'm just going to Simply run the
- 35:15Playbook and see if that works or not
- 35:17all right so now I have opened the
- 35:19terminal once again and I'm just going
- 35:20to execute the anible Playbook command
- 35:22so this is my anible playbook command
- 35:24and I'm just going to Simply hit enter
- 35:26uh type yes for accepting it and since
- 35:30I'm using the private key so I don't
- 35:31need to input my username and password
- 35:34and in case if you're not using the uh
- 35:37public and private key then you need to
- 35:39enter the username and password so that
- 35:41anible Playbook can run so that's the
- 35:43difference between this setup and the
- 35:44username password setup and this ncble
- 35:47Playbook might take a couple of minute
- 35:49to execute it so I'll just fast forward
- 35:52this uh session and I'll come back when
- 35:54this Playbook has executed successfully
- 35:57all right so here here you can see our
- 35:58ncble Playbook had just finished and you
- 36:00can see the status over here three Chang
- 36:03that means it has installed python it
- 36:05has created a directory and it has also
- 36:07installed the aach to that's why the
- 36:09count as three and just in case if
- 36:11Playbook fails and if there is there are
- 36:13any error then those errors will be
- 36:15visible over here in the red color font
- 36:17but here our ncble Playbook has
- 36:19successfully finished so I'm just going
- 36:21to clear the screen over here and we are
- 36:23just going to verify uh by logging into
- 36:26the server or just as s into the server
- 36:28so this is the command for SSH into the
- 36:30server I'm just going to hit enter and
- 36:32here you can see I'm just logged in and
- 36:34I'm just going to run the First Command
- 36:35that is python uh 3 version and here you
- 36:40can see python has been installed so our
- 36:41first task has been completed
- 36:43successfully the next command which I'm
- 36:44just going to run is the ls command and
- 36:46here you can see the directory basic
- 36:48HTTP server has been created so that
- 36:50directory I just wanted to create and
- 36:53the final thing which I need to verify
- 36:54is the I'll just clear the screen over
- 36:56here uh the system
- 36:59CTL uh
- 37:02status Apache 2 and here you can see the
- 37:07Apache 2 service is green that means our
- 37:09Apache 2 has been installed using anle
- 37:13so that's the verification part of our
- 37:15anible Playbook uh which we have just
- 37:17executed so now with that we have
- 37:19finished our chapter where we have seen
- 37:21like how to set up your anible project
- 37:23and how to execute your anible playbook
- 37:26now into the next chapter we will take a
- 37:28look onto the public and private key how
- 37:30to create your public and private key
- 37:32and how to associate those public and
- 37:34private key with your anible
- 37:37playbook all right so in this chapter we
- 37:39are going to talk about the SSH keys and
- 37:41the anible Playbook so whenever we talk
- 37:44about the SSH Keys then we are talking
- 37:46about the two keys one is the public key
- 37:48and one is the private key and since we
- 37:50are working with the an so the private
- 37:52key part will always remain with our
- 37:55anible Playbook which is local to you
- 37:58and the public key will always go onto
- 38:00the remote server so first of all we are
- 38:03just going to create those keys and then
- 38:04we are going to use the private key for
- 38:06our host inside our host file and the
- 38:09public key uh which we are going to copy
- 38:11it to our remote server let's switch
- 38:13over to our desktop and see the demo so
- 38:16here onto the screen you can see uh on
- 38:18the left hand side this is my anible
- 38:20playbook where my private key is and
- 38:22then we are going to execute the anible
- 38:24Playbook and then it is going to
- 38:26communicate with our remote server with
- 38:28a dedicated IP this IP is just an
- 38:30example and in this uh remote server we
- 38:33will have our public key but the
- 38:35question comes like how you are going to
- 38:36generate the SSH key so on the screen
- 38:39you will see on the left hand side this
- 38:41is the command which we are going to use
- 38:42to create our SSH keys so here we will
- 38:45be creating two keys so on the right
- 38:47hand side you will see anible demo and
- 38:49anbl demo. Pub so uh anible demo under _
- 38:54demo is going to be our private key and
- 38:56anore demo. Pub will be our public key
- 39:00so these two keys we will be creating
- 39:03and the public key we will try to copy
- 39:05it to our remote server so I'll switch
- 39:08over to my terminal and first of all
- 39:09let's create the SSH keys so here is my
- 39:12terminal and the command which I'm just
- 39:14going to run is the
- 39:15SSH keys
- 39:18in and here it will ask for the name of
- 39:20the keys which you want to create so I'm
- 39:22just going to use the same location I
- 39:25just wanted to create the uh keys on to
- 39:27the same location and the name of the
- 39:29key is
- 39:31anible uncore
- 39:33demo but you can specify your own path
- 39:36where you want to create those SSH keys
- 39:38I'm just creating it over here that that
- 39:40just for an example and simply hit enter
- 39:44I don't want to associate any pass
- 39:46phrase so I'm just going to keep it
- 39:47empty again empty and that's how we are
- 39:50just going to create the SSH keys so
- 39:52here you will see this is our first key
- 39:55uh that is ncore demo that is is our
- 39:57private key and this is going to be the
- 39:59second key which is our public key uh
- 40:02that is also present under SSH and it is
- 40:06ending with the extension. pub that
- 40:08means that is our public key now let's
- 40:10take a look onto the previous slide
- 40:12which I have shown so here uh we have
- 40:13created the anible demo that is our
- 40:15private key as well as the public key
- 40:18the next thing which we need to do is we
- 40:19need to copy the public key to our
- 40:21remote server that means we need to copy
- 40:23_ demo. pup key to our remote server
- 40:27server so I'm just going to use the SSH
- 40:29copy command to copy this public key to
- 40:31our remote server so this is my terminal
- 40:33and the command which I'm just going to
- 40:35use is SSH copy ID if I can could show
- 40:38you over here so this is the SSH copy ID
- 40:41command after that I need to use the I
- 40:43flag and here I need to specify the
- 40:45public key which is present onto my
- 40:47system so this is the public key which
- 40:49is present and after that I need to
- 40:50specify the username account which is
- 40:53present onto that remote server and the
- 40:55IP address of that particular remote
- 40:57server so once it is done then you just
- 41:00simply need to hit enter and it will ask
- 41:03for the password of our remote server so
- 41:06again I'm just going to copy the
- 41:07password from my notepad and paste it
- 41:09over
- 41:10here and here you can see the one key
- 41:13has been added so that means we have
- 41:14successfully added our public key to the
- 41:17remote server now coming back to the
- 41:20presentation once
- 41:21again so our the part of copying the
- 41:24public key to the remote server is over
- 41:26now we need to associate our private key
- 41:29with our anible Playbook okay so here's
- 41:32my anible playbook uh this is my anible
- 41:34playbook and where we need to associate
- 41:37our private key part so you need to go
- 41:39to the host file this is the IP address
- 41:42of my uh remote machine and this is the
- 41:46path actually this is the path of my
- 41:48private key so here this is the keyword
- 41:50anible SSH private key file that's the
- 41:53keyword from anible and here you need to
- 41:55specify the path of your private key so
- 41:58here I'm just going to use my new key
- 42:00that is analore demo that's going to be
- 42:03the my private key for this anible
- 42:05Playbook so I'm just going to open the
- 42:07terminal once again and I'm just going
- 42:08to rerun The anible Playbook with my new
- 42:12private key so here the Playbook command
- 42:14is again pretty simple anible Playbook
- 42:16then the inventory file where my host
- 42:18and the private key definition exist and
- 42:20the name of my playbook and I'm just
- 42:21simply going to hit enter and now this
- 42:24time it is going to use my newly created
- 42:26private key uh from my local machine to
- 42:28connect to our remote server so here you
- 42:31can see our uh command has successfully
- 42:33completed and this time I have reduced
- 42:35the Playbook so over here if you'll see
- 42:38so I'm just creating a very basic
- 42:40directory just to verify that I'm able
- 42:42to connect to remote server and I'm able
- 42:44to create a uh directory into my remote
- 42:47machine Let's SSH into the OR login into
- 42:50the server and verify that our directory
- 42:52has been created or not so I'm just
- 42:54going to use this command to SSH into my
- 42:56system
- 42:58and here we are able to log in into our
- 43:01remote server and I'm just going to run
- 43:02the ls command and here you can see our
- 43:04directory has been created with the name
- 43:06basic HTTP server all right so now you
- 43:08have seen like how to create the public
- 43:10key and the private key and how to use
- 43:12those keys to SSH into your remote
- 43:15server while you're running the anible
- 43:17Playbook but now into the next session
- 43:19we'll take a look on one of the most
- 43:21basic concept that is yml which is used
- 43:24for writing the anible Playbook so we'll
- 43:26take a look onto the example yml which I
- 43:29have used in previous session so that is
- 43:31going to be one of the basic yml and we
- 43:33will focus on the concept like what are
- 43:35the indentation rule what are the syntax
- 43:38you need to follow while writing your
- 43:39own anible Playbook so that is going to
- 43:42be the next session for our anible
- 43:46series all right so let's talk about the
- 43:48yml and why should we use yml for
- 43:51writing your own anible Playbook
- 43:53obviously the first question comes in my
- 43:55mind that what is yml and what it stands
- 43:58for so the full form of yml is yml and a
- 44:01markup language as the name suggests yml
- 44:04isn't a markup language so that means
- 44:06you don't need to use those traditional
- 44:08Syntax for writing your ymls so if there
- 44:11are no any markup syntax which you need
- 44:13to use for writing your own yml then
- 44:15what kind of a rules you should use for
- 44:17writing your yml so whenever you try to
- 44:20write a yml whether it's for your anible
- 44:23Playbook or if you're trying to Define
- 44:25any configuration so whenever you write
- 44:27yml then you need to carefully look on
- 44:30the indentations now you might be
- 44:32wondering like what is indentation so
- 44:34you might be familiar with the concept
- 44:36of indentation in some other programming
- 44:38languages but when we talk about the
- 44:40ymls then you need to follow that
- 44:42indentation rule very carefully so here
- 44:45onto the screen you can see the example
- 44:47of indentation which I took so here you
- 44:49will see item one and item two that that
- 44:51are starting on a certain horizontal
- 44:54position but sub item one and sub item
- 44:56two is is starting on a different
- 44:58horizontal position from item one and
- 45:00item two so these different horizontal
- 45:03position for each line item is called as
- 45:06indentation but you need to be really
- 45:08careful on defining the parent item and
- 45:10the child item so here the parent item
- 45:13I'm talking about is the item two is the
- 45:15parent and the sub item one and sub item
- 45:17two is the child so parent item will
- 45:20have a different horizontal position but
- 45:23sub item will have a different
- 45:24horizontal position so these horizontal
- 45:27Position will Define like which is
- 45:28parent and which is child and using this
- 45:31concept we are going to write our anible
- 45:33Playbook where we will be writing the
- 45:35parent item with the task and the
- 45:37description and then also we are going
- 45:39to write the child item inside our
- 45:41Playbook let's take an example where I
- 45:43have written a very basic yml for my
- 45:46anible so whenever you write a yml then
- 45:49you should start your first line with
- 45:51the three dashes so here you can see
- 45:52onto the screen my first line start with
- 45:55the three dashes moving to the next line
- 45:57and there where it comes the name so the
- 46:00name attribute defines like what your
- 46:02task does so here you can put a
- 46:05meaningful sentence like which describe
- 46:07what kind of a task you're trying to do
- 46:09so here I'm just trying to create a
- 46:11directory that's why I have put a
- 46:12description over here that is Meaningful
- 46:15that particular task but the second line
- 46:18always starts with a single Dash so it
- 46:21is always like single Dash and then name
- 46:23and then your description of that
- 46:25particular task now moving to the third
- 46:28line and the third line is depend upon
- 46:31like what kind of an anible Playbook you
- 46:33are writing so here I'm just trying to
- 46:35create a directory so here I need to use
- 46:38the module name so the module which uh I
- 46:41need to use for this Playbook is the
- 46:43file so that's why my third line I'm
- 46:45using the keyword that is file and that
- 46:48file module is responsible for creating
- 46:50or deleting the directory whenever I'm
- 46:53working with the anle so that's why the
- 46:56file name comes from and if you look
- 46:58carefully the line number third that
- 47:00starting at a certain horizontal
- 47:02position and that horizontal position is
- 47:04defined by a single tab all right so now
- 47:07we have defined the parent attribute as
- 47:09file the next to line where we are going
- 47:11to define the child attribute so
- 47:14whenever you're working with the file
- 47:15module of a anible then you need to
- 47:17define the two more attribute that is
- 47:20path and the state and if you look
- 47:22carefully over here the indentation of a
- 47:25path and the state attribute is little
- 47:28bit more than the parent attribute of
- 47:30file so here you will see I have put two
- 47:33tabs for defining path as well as two
- 47:36tabs for defining the state and with
- 47:38these two additional tabs or the
- 47:40indentation of a horizontal space you
- 47:43tell yml that these are going to be my
- 47:45child attribute so here path and the
- 47:48state are going to be the child for a
- 47:50file module and what's the purpose of a
- 47:52path and a state attribute so whenever
- 47:55you work with the file module and if if
- 47:56you're trying to create a directory then
- 47:58you need to specify the path like where
- 48:01you need to create your directory so
- 48:03then path attribute you're are just
- 48:05going to define the path where our
- 48:07directory will be created and the state
- 48:09attribute is going to Define that it
- 48:11will be created or it will be deleted
- 48:14okay so this is the simplest example
- 48:16which I have taken to explain how to
- 48:18write the yml for your anible playbook
- 48:21but considering the same example you can
- 48:24write your own anible Playbook where you
- 48:26can can have multiple tasks so this is
- 48:28just a one task where I'm creating a
- 48:30directory but you can have a n number of
- 48:33a task inside your playbook but the
- 48:35rules are same you just need to repeat
- 48:37this process and follow the same
- 48:40indentation rules for writing your next
- 48:42task for your anible playbook I hope the
- 48:45yml part is clear to you the next file
- 48:47which I'm talking about is the host file
- 48:50so in the host file where you trying to
- 48:52define the host where you want to
- 48:55execute your anible play the host file
- 48:57can exist with the name hosts or it can
- 49:00exist with the name hosts. inii and you
- 49:03can write the host file uh with yml and
- 49:06without yml also so the first example
- 49:09which you can see over here where I have
- 49:11written the host file without any yml
- 49:13rules so here I'm just trying to define
- 49:16the name of my host so here I have just
- 49:18taken an example gcp host and after that
- 49:22in the next line I have written the IP
- 49:24address of my remote machine so that's
- 49:26the simplest way of writing the host
- 49:29file without using yml syntax but the
- 49:31next example which I'm showing to you is
- 49:33little bit more complex and here I have
- 49:36taken the same example which I have
- 49:38written without yml as well as with yml
- 49:41so in the host file you can follow both
- 49:43the uh rules like with the yml and
- 49:45without yml and you can construct the
- 49:48parent and the child relationship
- 49:50between the different hosts so this is
- 49:52the way you can create your own host
- 49:55file so it just depends upon you like
- 49:57which kind of a snex you want to prefer
- 49:59but always remember try to put a
- 50:01meaningful name on the each host so that
- 50:04you can identify and you can pass the
- 50:06correct host while running your anible
- 50:08playbook so this is the host file which
- 50:11you can write either in vml or without
- 50:13using yml syntax I hope this session
- 50:16will help you to understand anible in a
- 50:18more better way and you can write your
- 50:20own anible playbooks with multiple task
- 50:23and the host file in the next session of
- 50:25this anible series we we will be talking
- 50:27about the handlers environment variables
- 50:30variables and if then else statement so
- 50:33stay tuned for that and if you haven't
- 50:35followed the anible series then there
- 50:36are some previous lab session on anible
- 50:39which you can go and check so see you
- 50:41into the next session till then take
- 50:42care and
- 50:44bye-bye hello there this is Rahul and
- 50:47today let's talk about the anible
- 50:49handlers before we jump into the anible
- 50:51handlers demo it's really important to
- 50:53understand what the an handlers are and
- 50:56when should we use the anible handlers
- 50:58inside your anible playbook let's take a
- 51:00very hypothetical scenario that you are
- 51:02having a website and you need to update
- 51:05the content onto your website you have a
- 51:07anible Playbook what it does it just
- 51:10copies the updated HTML file onto the
- 51:12server so that you can update the
- 51:14content of your website but there is one
- 51:16strict requirement that when you update
- 51:19the content or when you update the HTML
- 51:21file onto your application server then
- 51:23you need to restart the whole
- 51:25application server so that the updated
- 51:27content can reflect onto your website so
- 51:29how would you automate the whole process
- 51:31so the first task in this process is
- 51:33copy the updated HTML content onto your
- 51:36application server after that you once
- 51:39you have copied all the content you need
- 51:40to restart the application server so
- 51:43these two task you need to handle and to
- 51:45handle these kind of a task with anible
- 51:47you should use the anible handlers all
- 51:50right I will not make the things
- 51:51complicated so here onto the screen you
- 51:53can see the anible playbook for my
- 51:55anible Handler so the first task over
- 51:58here is to set up the enginex
- 52:00application server this is just an
- 52:02example that's why I'm keeping the
- 52:04things simple over here so my first task
- 52:06is to install the engine server and
- 52:08after that I'm just going to copy the
- 52:10content or the HTML file which I just
- 52:12want to update onto my application
- 52:15server so this is the second task which
- 52:17I will use to copy or to update the
- 52:19content on my website now you might be
- 52:21wondering like how should we incorporate
- 52:23the anible handlers over here so here I
- 52:26will will be using an attribute that is
- 52:28notifi and that attribute we need to
- 52:31Define what task it is going to do so
- 52:33here the task which I'm going to do is
- 52:35restart engine server because I have
- 52:38already updated the index.html onto my
- 52:41application server now you have used the
- 52:43notify attribute inside your anible
- 52:45playbook now you should Define that
- 52:47particular task so that you can restart
- 52:50the engine server and for that purpose
- 52:52we are just going to use the Handler so
- 52:54there is one more attribute which you
- 52:56can see over over here is the Handler
- 52:57and inside that Handler we are just
- 52:59going to write the task to restart the
- 53:01engine server all right so now you have
- 53:04a little bit of understanding on what
- 53:05the anible handlers are let's switch
- 53:07over to the desktop and see the anible
- 53:09playbook in demo let's start with the
- 53:11demo and onto the screen you can see the
- 53:13ncble Playbook but let's first start
- 53:15with the project structure so on the
- 53:17left hand side you can see this is the
- 53:18ncble Handler project which I have
- 53:20created and inside that anible handlers
- 53:22project you will find inventory and the
- 53:24roles trory so let's take take a look
- 53:26onto the inventory directory where I
- 53:28have defined the host file where I will
- 53:30be storing the remote server IP address
- 53:33or the remote server machine name so if
- 53:35you open this file then you will find
- 53:37the remote machine name over here just
- 53:39ignore the line number two because I
- 53:40have commented out all right so now we
- 53:43have seen that we will be running the
- 53:44anible Playbook onto this remote machine
- 53:47this is my AWS ec2 instance but just
- 53:49just you can just replace this uh
- 53:51machine name with any IP address of your
- 53:53remote server all right the next task is
- 53:57the roles so here in the roles I have
- 53:59created a role named Handler and
- 54:01whenever you create a role then you need
- 54:03to define the main. yml in any anible
- 54:06paybook so here I have created the main.
- 54:08yml so here I have written the task for
- 54:11installing my application server which
- 54:13is enginex which you can see over here
- 54:15and here I have just written the second
- 54:17task to copy the index.html the content
- 54:20of my website and the third task which I
- 54:23have written is to update the content of
- 54:25my website so here I have here I'm just
- 54:27trying to copy the updated HTML to the
- 54:30destination directory so this is the uh
- 54:32simplest anible Handler Playbook which I
- 54:35have written it over here and in the
- 54:37last task I'm just trying to call the
- 54:39anible Handler so that it can restart
- 54:42the engine server so this is an anible
- 54:45Handler Playbook which I'll be using for
- 54:47this particular demo now one thing I
- 54:49forgot to show you is where I have
- 54:50written the Handler so here you just
- 54:53need to open the main Playbook that is
- 54:54anible Handler Playbook IML and here I
- 54:57have return the Handler which is restart
- 54:59engine server so here you need to put
- 55:02the correct name over here which is
- 55:03restart Engen the same name I have used
- 55:06inside this notify attribute which is
- 55:09restart engine so you should put the
- 55:11same name in the both the places okay so
- 55:14coming back to the Handler so you need
- 55:15to use the attribute Handler you need to
- 55:17assign the name to the Handler and then
- 55:19you need to do Define like what kind of
- 55:22things you want to do with your handlers
- 55:24so here I just wanted to restart the
- 55:26engine service so the name uh the
- 55:28attribute which I'm just going to use is
- 55:30the engine service name over here and
- 55:32the state is restarted which means anel
- 55:35is going to instruct that please restart
- 55:37this particular service so this is how
- 55:40uh I'm just going to define or structure
- 55:42my anible handlers Playbook and also
- 55:44I'll put the GitHub repository link of
- 55:46this particular repo into the
- 55:48description section so feel free to copy
- 55:50that particular raer to use this anible
- 55:52Handler example now we have seen the
- 55:54anible handlers uh Playbook example
- 55:57let's try to run this particular anible
- 55:59Playbook and just see how the things
- 56:01works so just to give you a little bit
- 56:03brief so first it is going to install
- 56:05the engine server after that it is going
- 56:07to copy that particular index.html and
- 56:10as soon as we update that particular
- 56:12index.html with updated content then it
- 56:15should restart our genenic server so
- 56:18that's the whole purpose of our anible
- 56:20Handler because we just wanted to
- 56:22restart something based on certain
- 56:24action so that action is we have updated
- 56:26the HTML content and that's for the
- 56:29reason we need a restart to our engine X
- 56:31server okay so this is my terminal and
- 56:34I'm just going to run the ncble Playbook
- 56:35command so here this is my ncble
- 56:37playbook command so that's the keyword
- 56:39that is ncble Playbook after that you
- 56:41need to specify the name of the
- 56:43inventory uh that's the inventory flag
- 56:45which you first need to use and after
- 56:47that you need to specify the host file
- 56:49where your host file decides and if you
- 56:52go back over here so here is the
- 56:54inventory and this is the host file
- 56:56where you have your remote server which
- 56:57I have already mentioned okay Switching
- 57:00back to the terminal so after that you
- 57:02need to specify the name of the Playbook
- 57:04so this is the name of the Playbook and
- 57:05I can show you once again so this is my
- 57:07anible Handler project and this is the
- 57:09anible Handler Playbook which I'm using
- 57:11right now so let's switch back to
- 57:13terminal and this is the command which
- 57:14I'll be executing to test my nzl Handler
- 57:18so simply hit enter and if you're this
- 57:21is the first time you're connecting to
- 57:22your remote server then it is asking you
- 57:24to do you really want to connect so
- 57:25simply type yes all right so as you can
- 57:28see my anible playbook had just finished
- 57:30so let's start each task one by one so
- 57:33here this is the first task update uh uh
- 57:36at cache and install engine so this is
- 57:38the first task which I have written so
- 57:40let me open the Playbook so yeah this is
- 57:42the first task which I just wanted to
- 57:44execute and that will install the
- 57:45enginex so if you go to the terminal so
- 57:48here you can see this first task has
- 57:50been executed second task is to copy the
- 57:53index.html and remember this is the
- 57:55first time we are copying the index.html
- 57:58and we don't need to restart so that's
- 58:00why uh this task will not call the
- 58:02anible Handler so this is the second
- 58:04task we just wanted to execute so just
- 58:06check uh this is the index.html we just
- 58:10wanted to copy and this index.html is
- 58:13present into the same directory where I
- 58:14have defined the task or the main. yml
- 58:17all right let's go further after copying
- 58:21the index.html the next task is to copy
- 58:24the updated HTML to the destination
- 58:26directory and just take a look so this
- 58:28is the updated HTML which is present
- 58:31into the same directory and I'm also I
- 58:33just wanted to copy into the same
- 58:35directory where my index.html is so it
- 58:37will just rename this direct uh
- 58:39particular file which is update. HTML to
- 58:42the
- 58:43index.html once it execute all right so
- 58:46as soon as it copies the update. HTML it
- 58:49should call the restart engine X Handler
- 58:52so let's take a look onto the terminal
- 58:54so here it is copying file first of all
- 58:57and after that it is calling the restart
- 58:59enginex Handler so let's take a look
- 59:02onto the Handler so which is present
- 59:04over here so this is the Handler and the
- 59:06name of the task is restart engine so
- 59:08let's take a look onto the terminal once
- 59:10again so here you can see it is calling
- 59:12the restart engine server Handler so
- 59:15this is how this whole anible Playbook
- 59:18work so where uh you have created or we
- 59:21where you have installed the engine
- 59:22server and then you have copied the
- 59:24index.html then you have updated the
- 59:27index.html and after the update you need
- 59:29a restart and for that purpose you have
- 59:32used the uh en Handler so well this is
- 59:35just an idea which I just wanted to show
- 59:38you like how the anible handlers work
- 59:40but this idea can be used for any other
- 59:43different use cases so the idea is
- 59:45pretty simple like whenever you want to
- 59:48execute something which is dependent on
- 59:50some other task then you should use the
- 59:52anible Handler so here the dependent
- 59:55task was to
- 59:56trigger the anible Handler when you
- 59:58updated the particular content of the
- 1:00:01file so here the content is index. stml
- 1:00:04so as soon as I have updated the
- 1:00:05index.html so I need to restart the
- 1:00:08engine server so that's the dependency I
- 1:00:10had between those tars so you have a if
- 1:00:12you have a similar dependency in your
- 1:00:15project then you could use the anible
- 1:00:17handlers for your own purpose and it the
- 1:00:20limitation of anable Handler is not up
- 1:00:22to restarting a server you can trigger
- 1:00:24the mail you can execute the bch so
- 1:00:26there are a number of possibilities
- 1:00:28which you can execute or which you can
- 1:00:29Implement with the anible handlers I
- 1:00:32hope you like the today's session onto
- 1:00:33the anible Handler and how to use those
- 1:00:36in the next session we will be taking a
- 1:00:38look onto the anible variables so see
- 1:00:40you into the next session of our anible
- 1:00:42till then take care and
- 1:00:45bye-bye hello there this is Rahul and
- 1:00:48let's continue with our anible series
- 1:00:50and in this session we are going to talk
- 1:00:51about the anible variables so what we
- 1:00:54are going to cover into this sensible
- 1:00:56variable session so we will first start
- 1:00:58with the very basic data types that is
- 1:01:00string Boolean and then gradually we
- 1:01:02will take a look onto the list and the
- 1:01:04dictionaries also and furthermore into
- 1:01:07this session we are also going to take a
- 1:01:08look how to pass the variables at a
- 1:01:10runtime using the command line and as
- 1:01:12well as how to access the variables from
- 1:01:14your vars file and at last we are going
- 1:01:16to take a look onto the variables
- 1:01:18precedence so this is going to be a
- 1:01:20really comprehensive guide onto the
- 1:01:21anible variables all right now switching
- 1:01:23over to the desktop and onto this script
- 1:01:25screen you can see this is the project
- 1:01:27which I have created where I have
- 1:01:28created a lots of variables and the
- 1:01:31sample files over here so I'm just going
- 1:01:33to share this link of this GitHub
- 1:01:35repository into the description section
- 1:01:37so feel free to use this project and you
- 1:01:39can reference this example from this
- 1:01:41GitHub repository let's start with a
- 1:01:43very simple example so here onto the
- 1:01:45screen you can see this is the Playbook
- 1:01:46which I have written and the first
- 1:01:48variable which I'm just going to create
- 1:01:50is the string variable and here onto the
- 1:01:52line number 11 you will see I have
- 1:01:54created a variable and the the name of
- 1:01:56the variable which I have kept over here
- 1:01:58is the main Playbook variable so that's
- 1:02:00the name of my variable and the value I
- 1:02:02have assigned over here is the hellow
- 1:02:04world from U main Playbook so this is
- 1:02:06the simplest variable which I have
- 1:02:08created inside my playbook and here if
- 1:02:10you take a look carefully the line
- 1:02:12number nine here I have to put vs as a
- 1:02:15keyword inside your playbook so this is
- 1:02:17the attribute which tells anle Playbook
- 1:02:20that now everything below the vars or
- 1:02:22inside the vs is going to be the
- 1:02:24variables so this is the first way of
- 1:02:27defining a variable inside a anible
- 1:02:29Playbook now the question comes like how
- 1:02:31you're going to use that anible variable
- 1:02:33which you have created just now so here
- 1:02:35inside the task which is line number 13
- 1:02:38here I have created a task which is a
- 1:02:40very simple task I keeping the Playbook
- 1:02:42very simple over here and inside that I
- 1:02:44have put a debug parameter over here and
- 1:02:46inside that I have used that particular
- 1:02:48variable so if you check the name of the
- 1:02:50variable that is mainor Playbook _
- 1:02:53variable so that's the name of my
- 1:02:54variable and that's the variable which I
- 1:02:56have used at line number 11 so this is
- 1:02:58the simplest way you can create a
- 1:03:00variable and you can use that particular
- 1:03:02variable inside your task now how to
- 1:03:04verify and how to test this Playbook so
- 1:03:06there is a read me which I have already
- 1:03:08created inside this anible project
- 1:03:10example so here you can just run the
- 1:03:13first Playbook command because this is
- 1:03:14the simplest variable example which I'm
- 1:03:17taking that's why you just use this
- 1:03:18First Command over here and there are
- 1:03:20couple of more example I have written
- 1:03:22over here but those we will take a look
- 1:03:24later but just to keep the simple this
- 1:03:26is the command which I'm just going to
- 1:03:27use to run my playbook and the command
- 1:03:29is pretty simple if I can go over here
- 1:03:32and if I do the softw then this is the
- 1:03:35inventory where I'm putting my host file
- 1:03:37but since this uh Playbook is running on
- 1:03:39my Local Host so you don't really need
- 1:03:41to have a remote server over there and
- 1:03:44secondly this is the name of my playbook
- 1:03:46that is ncble variable Playbook yml so
- 1:03:49that's the name of my playbook which you
- 1:03:50can see over here also so the Playbook
- 1:03:52command uh Playbook run command is
- 1:03:54pretty simple over here let's copy this
- 1:03:56command from here and go to your
- 1:03:59terminal so this is my terminal and I'm
- 1:04:01just going to run this command over here
- 1:04:03to execute my
- 1:04:05playbook and here we need to verify the
- 1:04:07task so the task which we were uh
- 1:04:09referring to is string variable from
- 1:04:11Main Playbook variable and here you can
- 1:04:14see the output which I have printed the
- 1:04:16value of that particular variable and
- 1:04:19that the value is Hello World in main
- 1:04:21Playbook so let's check back into our
- 1:04:23anible Playbook so if you come over here
- 1:04:25so this this is the name of the task
- 1:04:26which we have just seen and the value of
- 1:04:29the variable so this is how you're just
- 1:04:31going to create a very simple variable
- 1:04:33inside your playbook and you're just
- 1:04:34going to use that Playbook or that
- 1:04:36variable inside your playbook moving
- 1:04:38further now we have seen the string
- 1:04:40variable let's try to create an Boolean
- 1:04:42variable so here onto the screen you can
- 1:04:44see I have created a one more Boolean
- 1:04:46variable and the name of the variable
- 1:04:48which I have kept it is like is enabled
- 1:04:50and the value I have assigned is true
- 1:04:53and here at the line number 21 till 25
- 1:04:55you can see this is how I'm just going
- 1:04:57to use that particular Boolean variable
- 1:04:59so the here is the name of my task which
- 1:05:01you can keep anything and the message
- 1:05:03which I'm just going to print over here
- 1:05:05is variable is true but this message
- 1:05:07will be printed when this uh particular
- 1:05:09value of that particular variable is pro
- 1:05:12so here you need to put a van condition
- 1:05:14for the bullan variables So based on
- 1:05:17this uh value of that particular bullan
- 1:05:19variable this particular message will be
- 1:05:21printed so here the value is true that
- 1:05:23means our message should be printed onto
- 1:05:25our cons
- 1:05:26okay so I'm just going to open my
- 1:05:27terminal over here and I'm just going to
- 1:05:29run the same command which I have just
- 1:05:31executed previously and just check the
- 1:05:33uh
- 1:05:34task and here you can see the task is
- 1:05:36Boolean variable and the value which I
- 1:05:38have got over here is Val variable is
- 1:05:41true that means uh the True Value has
- 1:05:43been satisfied and I'm able to print the
- 1:05:45message I'm just going to clear the
- 1:05:47screen and next thing I'm just going to
- 1:05:48do I'm just going to set the value to
- 1:05:50the false and let's verify the task once
- 1:05:52again so here just go back to the
- 1:05:55Playbook and set the value to false and
- 1:05:58go to terminal and rerun the same
- 1:06:00command over here so here you can see uh
- 1:06:04so Boolean variable task has been
- 1:06:06executed but nothing got printed over
- 1:06:08here into the message so that means uh
- 1:06:11this is how uh bullan is evaluated based
- 1:06:13on true and false if you set the value
- 1:06:15to true then that particular message is
- 1:06:17getting printed and if you set it to the
- 1:06:19false then that particular message is
- 1:06:21not going to print moving to the next
- 1:06:22variable which is our list and here you
- 1:06:25can see uh line number 17 till line
- 1:06:27number 20 we have created a variable
- 1:06:29that is list and the name of the list is
- 1:06:31fruits and inside that particular list I
- 1:06:33have added three uh fruits actually
- 1:06:36apple banana and orange so this is how
- 1:06:38you are just going to create a list
- 1:06:39variable inside your anible and the task
- 1:06:43is going to be pretty much same so here
- 1:06:45I have created a task where I'm just
- 1:06:46going to use that particular variable
- 1:06:48and here the name of the variable which
- 1:06:50I have used over here is fruits so let's
- 1:06:52verify this particular variable go back
- 1:06:55to terminal and run the command and here
- 1:06:59you can see uh we have printed the name
- 1:07:01or the list of fruit variables over here
- 1:07:04now we have seen the list variable but
- 1:07:06is there possibility in anible to access
- 1:07:09the index position or a particular
- 1:07:11element in the particular list so here
- 1:07:13we have created a list of fruits but if
- 1:07:16I want to access the particular element
- 1:07:18inside that list then how can I do that
- 1:07:21so nle provides a way and you need to
- 1:07:24use the index position so so here you
- 1:07:25can see I have created a one more task
- 1:07:27and inside that task I have uh specified
- 1:07:30the position of that particular element
- 1:07:32which I want to access inside the list
- 1:07:34so here I have mentioned zero so which
- 1:07:36means I'm trying to access the Apple uh
- 1:07:39uh fruit inside that particular list so
- 1:07:41let's go back to the terminal and verify
- 1:07:43whether it works or not so I'll just
- 1:07:46clear the screen and I run the Playbook
- 1:07:49and here you can see uh the previous
- 1:07:51task where we have printed all the
- 1:07:52element present inside the list and in
- 1:07:55in in this task we are just printing
- 1:07:57that particular element which is present
- 1:07:59inside the list and that is Apple so
- 1:08:01this is how you can access the elements
- 1:08:03uh inside the list with the index
- 1:08:05positions moving to the next variable
- 1:08:07and this time we are going to take an
- 1:08:09example of a dictionary variable so here
- 1:08:11onto the screen you can see from the
- 1:08:12line number 22 till 26 I have created a
- 1:08:15dictionary and what is dictionary so
- 1:08:17here this is the name of the dictionary
- 1:08:19that is fruit prices and inside that
- 1:08:22dictionary you will see the price of
- 1:08:23Apple uh with its value
- 1:08:26but just remember from the previous
- 1:08:27thing so previous uh list variable was
- 1:08:30only containing a list of a single
- 1:08:32element so that is apple banana oranges
- 1:08:35there was no price associated with it
- 1:08:37but here in the dictionary you have a
- 1:08:39dictionary name that is fruit prices and
- 1:08:41inside that dictionary you will find the
- 1:08:43name of the fruit along with its prices
- 1:08:46so this is how we are just going to
- 1:08:47create a dictionary inside the anible
- 1:08:49Playbook let's scroll further down into
- 1:08:52the Playbook and print the value of a
- 1:08:53dictionary so here I have created a one
- 1:08:55more task that is dictionary variable
- 1:08:57and accessing the value of the those
- 1:08:59particular dictionaries and this is the
- 1:09:01name of that particular dictionary
- 1:09:03variable which I'm going to use so I'm
- 1:09:05just going to head back to terminal and
- 1:09:07I'm just going to run the Playbook once
- 1:09:10again and here you can see the
- 1:09:12dictionary variable task has been
- 1:09:14executed successfully and here I can see
- 1:09:16the values of my particular dictionary
- 1:09:18so this is how you are going to create a
- 1:09:20dictionary and this is how you're going
- 1:09:21to access that particular dictionary
- 1:09:23variable inside your playbook now let's
- 1:09:25play around this dictionary variable so
- 1:09:27I'll scroll up and here you can see this
- 1:09:29is the dictionary we are having so what
- 1:09:31if is there any possibility to access
- 1:09:34that particular element inside that
- 1:09:36dictionary so here I would like to
- 1:09:38access only Apple so is it possible so
- 1:09:41my answer is yes anible provides you a
- 1:09:43way to access a particular element
- 1:09:45present inside the dictionary so here uh
- 1:09:48I have created a one more task for
- 1:09:50accessing that particular variable that
- 1:09:51is Apple inside the dictionary so what
- 1:09:54you need to do is you just need to
- 1:09:55create the task with the name and then
- 1:09:57you need to uh put the variable uh of
- 1:10:00variable name of that particular
- 1:10:02dictionary along with the particular
- 1:10:04element name that is Apple so that's how
- 1:10:07you're going to access that particular
- 1:10:08element which is present inside that
- 1:10:10particular dictionary so I'm just going
- 1:10:12to head over to terminal to verify this
- 1:10:14so let's head over here and run the
- 1:10:17Playbook and here you can see uh the
- 1:10:19dictionary variable accessing individual
- 1:10:22specific field so here you can see the
- 1:10:23value of that particular element element
- 1:10:25that is Apple and that is 0.5 so this is
- 1:10:28how you're just going to access that
- 1:10:29particular element which is present
- 1:10:31inside your dictionary and this concept
- 1:10:33is pretty much same uh if you compare
- 1:10:35with the list when you're trying to
- 1:10:36access the Apple present inside that
- 1:10:38list so this is how you're going to uh
- 1:10:40use that particular accessing of that
- 1:10:42particular element inside the dictionary
- 1:10:44now I'm just going to take a one more
- 1:10:46example on top of that particular
- 1:10:48dictionary so where I'm just going to
- 1:10:49take a one more variable so if you are
- 1:10:52familiar with any programming languages
- 1:10:54then you create a multi variables and
- 1:10:56then you assign a particular value of
- 1:10:58that variable to any other variable so
- 1:11:01here uh we have created a dictionary and
- 1:11:03from that dictionary I'm just going to f
- 1:11:05the value of that apple and then assign
- 1:11:08that value to another variable so here
- 1:11:10onto the screen you can see the line
- 1:11:12number 54 till 57 so here I'm just
- 1:11:15trying to fetch the value of that
- 1:11:17particular apple and then assign that
- 1:11:19value of that particular variable to
- 1:11:21another variable so that we call it as a
- 1:11:23register variable in place and so here
- 1:11:27you need to use the keyword register so
- 1:11:29that you can register that particular
- 1:11:31variable and this particular value which
- 1:11:33is present over here is going to be
- 1:11:35assigned to this particular variable and
- 1:11:37to verify this what we are going to do
- 1:11:39we are just going to put or we are just
- 1:11:41going to print that value of that
- 1:11:43registered variable so here I'm just
- 1:11:45going to print it onto my command line
- 1:11:47so this is how you are going to do the
- 1:11:49variable assignment to any other
- 1:11:51variable using the registered variable
- 1:11:53in the nle Playbook okay let's let's
- 1:11:55open the terminal and run the Playbook
- 1:11:57to verify the value so I'm just going to
- 1:11:58clear this one and run the
- 1:12:01Playbook and here you can see uh the get
- 1:12:04the price of an apple and print the
- 1:12:06value of a registered variable so this
- 1:12:09particular task here you can see there
- 1:12:11is nothing got printed so if you can
- 1:12:13check over here so in this particular
- 1:12:15task we are just doing the assignment we
- 1:12:17are not trying to print anything so we
- 1:12:19are just trying to assign the value of
- 1:12:21Apple to the registered variable and
- 1:12:23after that in the next task which is the
- 1:12:25print the value of a registered variable
- 1:12:27where we are just going to print the
- 1:12:28value of that particular registered
- 1:12:30variable so which is which you can see
- 1:12:32and verify from this particular terminal
- 1:12:35so this is how you're just going to play
- 1:12:36around with a multiple variable
- 1:12:38assignment into your an Playbook all
- 1:12:40right so now we have seen the uh
- 1:12:42register variable in anible let's
- 1:12:45increase the complexity of a variables a
- 1:12:47little bit more and here we are just
- 1:12:48going to play around with a couple of
- 1:12:50dictionaries so the first dictionary we
- 1:12:52will take is the for price list and the
- 1:12:55second dictionary which I'm just going
- 1:12:56to test uh which I'm just going to take
- 1:12:58is the nested variable dictionary over
- 1:13:01here so here you can see this is the
- 1:13:03fruit basket and this is the first
- 1:13:05element uh inside that particular fruit
- 1:13:07basket and there is a name and then
- 1:13:09inside that there is a particular list
- 1:13:11of fruits which is apple and orange and
- 1:13:13similarly there is one more fruit basket
- 1:13:15for Yen and there are fruits like banana
- 1:13:18and apple inside that fruit basket so
- 1:13:21what I'm just going to do there is a
- 1:13:22scenario which I'm just going to take so
- 1:13:24first of all I'm just going to fetch the
- 1:13:26fruit basket then I'm just going to
- 1:13:28fetch the uh first element that is the
- 1:13:31John's basket and inside that basket I'm
- 1:13:34just going to fetch the apple and after
- 1:13:37fetching this particular fruit from this
- 1:13:39basket I'm just going to use the fruit
- 1:13:41price list to fetch the prices of that
- 1:13:44particular Apple so that's the scenario
- 1:13:47and I just wanted to show you that this
- 1:13:48is how you're just going to mass around
- 1:13:50the dictionaries and you're just going
- 1:13:52to iterate on those particular complex
- 1:13:54dictionaries all right so now how to
- 1:13:56achieve that so if you go down into the
- 1:13:58task so here I have created a particular
- 1:14:00task and this task is pretty simple but
- 1:14:03uh just to give you the context so first
- 1:14:05of all I'm just going to access the
- 1:14:06fruit basket so that is this fruit fruit
- 1:14:09basket and if you go up over here so
- 1:14:12this is the fruit basket and here I'm
- 1:14:13just trying to access the zeroth element
- 1:14:16that is John's basket so I'm just going
- 1:14:18to put zero and after that I'm just
- 1:14:20going to put one more zero into the
- 1:14:22fruits so let's go here and and here you
- 1:14:25can see the fruit basket I just wanted
- 1:14:27to access the John's fruit basket and
- 1:14:30after that in the fruits basket I'm just
- 1:14:32going to access the zero element that is
- 1:14:35Apple so this particular uh this
- 1:14:38particular expression is going to return
- 1:14:40me apple and once I get that particular
- 1:14:43value that is Apple then I'm just going
- 1:14:44to apply it to the fruit prices so that
- 1:14:47is our again uh if you go up over here
- 1:14:49that fruit prices is again another
- 1:14:51dictionary and inside the dictionary I'm
- 1:14:53just going to mention that I I just
- 1:14:55wanted to fetch the Apple so this
- 1:14:58particular whole expression is going to
- 1:15:01return me apple and once that has been
- 1:15:04return returned and then this expression
- 1:15:05is going to return me 0.5 which is the
- 1:15:08value of that particular Apple all right
- 1:15:10so now we have seen like how to use that
- 1:15:13particular uh expression and access the
- 1:15:15nasted element inside the dictionary so
- 1:15:17let's run I'll just undo the task and
- 1:15:19let's go to terminal and run this thing
- 1:15:22I'll just clear
- 1:15:23it
- 1:15:25and run it and here you can see uh where
- 1:15:29it is yeah get the value of a apple from
- 1:15:31a nested variable so that was the task
- 1:15:33and which you can see over here get the
- 1:15:35value from a nested variable and if I go
- 1:15:38back to terminal once again so here you
- 1:15:39can see the value of that particular uh
- 1:15:42fruit which is Apple so this is how we
- 1:15:44just going to access the nested elements
- 1:15:47inside the uh dictionary all right so
- 1:15:49now we are bit familiar with the uh our
- 1:15:52dictionary variable and the nested
- 1:15:53dictionary variable and how to access
- 1:15:55them the next thing which I'm just going
- 1:15:57to show you is the Ginger 2 filters so
- 1:16:00here uh this is the task which I have
- 1:16:01created for Ginger 2 filters and these
- 1:16:03Ginger to filters are really helpful
- 1:16:05when you when you want to do some kind
- 1:16:07of a string manipulation like converting
- 1:16:09lower case to upper case so these Ginger
- 1:16:11to filters are really handy but that's
- 1:16:14converting to lower case and uppercase
- 1:16:16is just one example or one use case but
- 1:16:18there are and number of application of
- 1:16:20Ginger 2 filter so the idea is just to
- 1:16:23learn the concept of a ginger two
- 1:16:25filters over here so here what I'm going
- 1:16:27to do I'm just going to create I'm just
- 1:16:29going to access the keys of my fruit
- 1:16:31prices so if you go over here so this is
- 1:16:34our fruit prices dictionary and the keys
- 1:16:36are apple banana and orange so I'm just
- 1:16:38going to access only the keys after that
- 1:16:41I'm just going to convert that
- 1:16:43particular keys to the list so here if
- 1:16:45you see the pipe then this pipe is a
- 1:16:47Ginger 2 filter which is converting this
- 1:16:50particular keys to list after that I'm
- 1:16:54just going to use a again the same
- 1:16:55Ginger to filter and convert it into
- 1:16:57uppercase so this is how I'm just going
- 1:16:59to do the uppercase conversion of my
- 1:17:01keys and finally I'm just going to print
- 1:17:03it in I'm just going to convert it into
- 1:17:05again a list and this particular task is
- 1:17:07going to print the value of that
- 1:17:09particular list now let's run this
- 1:17:11particular Playbook once again and I'm
- 1:17:13just going to oh the screen is already
- 1:17:15clear so I'm just going to run the
- 1:17:16Playbook
- 1:17:17command and here you can see using the
- 1:17:20ginger to filters on variables so this
- 1:17:22is the name of the keys like apple
- 1:17:24banana orange and which got converted
- 1:17:26into the uppercase and these are Now
- 1:17:28list these are not dictionaries anymore
- 1:17:30so this is how you're just going to use
- 1:17:32the ginger to filters inside your anible
- 1:17:34playbook moving further so till now you
- 1:17:37have seen like how to create the
- 1:17:38variables inside your ncble playbook and
- 1:17:41how to access those particular variable
- 1:17:43now if I talk about the scenario if you
- 1:17:46want to create a variable inside a
- 1:17:48different Wars file and you don't want
- 1:17:50to create the variable inside the same
- 1:17:52Playbook so then how you're going to do
- 1:17:54that so if you take the next example
- 1:17:56which I'm just going to show you over
- 1:17:57here so this is the sixth example which
- 1:18:00I'm just taking where I'm just going to
- 1:18:01declare the variable or I'm just going
- 1:18:03to create the variable in a different
- 1:18:04Wars file so the name of the file is my
- 1:18:07wars. yml and if I open that file so
- 1:18:11inside this anible variable project that
- 1:18:13there is a file which exists like my
- 1:18:15wars. yml and here I have created that
- 1:18:18particular variable so this is the name
- 1:18:19of my variable that is vs from my my
- 1:18:22Wars yml so this is just a very a dummy
- 1:18:25name I have taken and this is the value
- 1:18:27which I have assigned to that particular
- 1:18:28variable so this particular variable
- 1:18:30doesn't exist into my main Playbook but
- 1:18:33it exist into a separate Wars or
- 1:18:35variables
- 1:18:36file so how to access those particular
- 1:18:40variables so first of all you need to
- 1:18:41specify the reference or the location of
- 1:18:44that particular variable or the wars
- 1:18:46file so here you need to first use the
- 1:18:48attribute that is vs file and here you
- 1:18:50can specify the variable file name that
- 1:18:53is my wars. y
- 1:18:55and here you can reference or you can
- 1:18:57include multiple Wars files so if you
- 1:18:59have more than one file then you can
- 1:19:01just keep on adding a more uh the vs
- 1:19:04file name over here and anel will be
- 1:19:06able to include those variables file
- 1:19:08inside your playbook so here I have just
- 1:19:10taken a one example so here there is a
- 1:19:12one file and inside that I have created
- 1:19:14a one variable and how to access that
- 1:19:17particular variable so accessing part is
- 1:19:19still the same your task is going to be
- 1:19:21look like still the same so here I have
- 1:19:23just created a one more task and here I
- 1:19:25have used the variable that is vs from
- 1:19:27my Wars file so if you copy this and if
- 1:19:29you go over here then you should be able
- 1:19:31to find it so this is the variable which
- 1:19:33I'm trying to access it all right so now
- 1:19:36you have seen this particular example
- 1:19:37let's go to terminal and execute it so
- 1:19:40I'll clear
- 1:19:43it and here you can see this is the name
- 1:19:46of the variable and this is the value of
- 1:19:48that particular variable so idea was
- 1:19:50over here is like how to include or how
- 1:19:53to use the variable file which is
- 1:19:55external not external but at least
- 1:19:56present into the different directory of
- 1:19:58that particular project and references
- 1:20:00into your anle playable so this is how
- 1:20:03your just going to do the inclusion of
- 1:20:05that particular variable file all right
- 1:20:08so now we have seen like how to create a
- 1:20:09variable inside the Playbook how to
- 1:20:11create a variable inside a variable file
- 1:20:14but next thing which I'm just going to
- 1:20:15show you like how to pass the variable
- 1:20:18at run time so here I have just created
- 1:20:21a one task the task is pretty simple
- 1:20:23again so this is the name of the task
- 1:20:25and this is the value of that variable
- 1:20:26version but the key thing over here is
- 1:20:29that I have not declared this version
- 1:20:30variable inside this Playbook so if you
- 1:20:33will not just find any reference over
- 1:20:35here if you go to the top over so here
- 1:20:37you can see there is no reference to
- 1:20:39that version variable and if you go to
- 1:20:41the my WS files over here then also
- 1:20:43there is no reference to the version
- 1:20:45variable so this particular version
- 1:20:47variable which you see over here uh at
- 1:20:50line number 96 so this version variable
- 1:20:53I have not declared anywhere here but
- 1:20:55I'm just going to pass that particular
- 1:20:57value of that variable at run time and
- 1:21:00how to do that so if you open this
- 1:21:02particular readme file so till now we
- 1:21:04were just simply executing this anible
- 1:21:06Playbook but here at the line number 10
- 1:21:09this is the Playbook command which I'm
- 1:21:11just going to use to pass the variable
- 1:21:13at run time and to do that you what you
- 1:21:16need to do you just need to add extra
- 1:21:19flags that is extra vars for extra
- 1:21:21variable and here you need to specify
- 1:21:23the name of the variable that is version
- 1:21:25and its value and similarly you can pass
- 1:21:28one more variable other variable and the
- 1:21:30value that is who so here you can pass
- 1:21:33the runtime variable to your anible
- 1:21:35playbook and you cannot just only pass
- 1:21:37one variable but you can pass multiple
- 1:21:39variables let's copy this command from
- 1:21:41this particular R me and go to your
- 1:21:44terminal over here and clear the screen
- 1:21:47and paste the
- 1:21:49command and here you can see get the
- 1:21:51value from a runtime and if you go back
- 1:21:54over here here so get the value from the
- 1:21:56runtime and the variable is version and
- 1:21:58you can see the value that is 1.0 and if
- 1:22:02I show you the again the readme file
- 1:22:04then you can see 1.0 so this is how
- 1:22:07you're just going to pass the Val uh
- 1:22:09variable at a run time using your ncble
- 1:22:11playbook command and you can access the
- 1:22:13same variable inside your playbook all
- 1:22:15right so now we have seen like how to
- 1:22:17pass the variable at a runtime from the
- 1:22:19command line the next concept I'm
- 1:22:21talking about is can you pass the
- 1:22:23variable file from the command line so
- 1:22:26yes you can do that in your anible
- 1:22:28playbook so here I have already created
- 1:22:30a my Wars file that is present inside my
- 1:22:33project and inside that war file I have
- 1:22:35created a variable that is other
- 1:22:37variable and the value is four so here
- 1:22:40what I'm going to do I'm just going to
- 1:22:41print the value of other variable but
- 1:22:44I'm just going to run my ncble playbook
- 1:22:46command a little bit different so here
- 1:22:48in the read me you will find a one more
- 1:22:50command and here I have used the extra
- 1:22:53vars and here I have pass the yml file
- 1:22:56so instead of passing an runtime
- 1:22:58variable individually I'm just going to
- 1:23:00pass the complete yml file name at
- 1:23:03runtime so this is the way you should do
- 1:23:06it and you can even pass the Json file
- 1:23:08also so what you need to do you just
- 1:23:09need to put at the red sign and after
- 1:23:11dat the name of that particular file but
- 1:23:13always remember try to put the correct
- 1:23:15path so if this file is present inside
- 1:23:17some of the directory then just use that
- 1:23:20particular path relative to that your
- 1:23:22anible label but anyway this Playbook is
- 1:23:25available over here and uh this yml is
- 1:23:28also available onto the same level so
- 1:23:30I'm just going to go to terminal I'm
- 1:23:32just going to clear the screen and I'm
- 1:23:34just going to run the
- 1:23:35command and here you can see the value
- 1:23:38has been printed the other variable F
- 1:23:40and the print the value of a variable
- 1:23:42when v file is passed at a run time so
- 1:23:44that's the name of that particular task
- 1:23:47so this is how you're just going to uh
- 1:23:49create uh not create but uh you're just
- 1:23:51going to pass the variable uh from the
- 1:23:53command line so this is what I just
- 1:23:55wanted to show you uh this is one more
- 1:23:58example where you can use the runtime
- 1:23:59variables now the last thing which I
- 1:24:01just wanted to cover into this variable
- 1:24:03session is the variable precedence so
- 1:24:05how the variable precedence happen when
- 1:24:07you have multiple variables with the
- 1:24:09same name so let's take an example to
- 1:24:12understand this so in the my Wars files
- 1:24:14I have created a variable that is other
- 1:24:16variable with the value F but in the
- 1:24:19readme file at a runtime I'm just
- 1:24:21passing the same variable with the value
- 1:24:23f world so again I'm using the same
- 1:24:26variable but I'm trying to pass the two
- 1:24:29values one is present from the wars file
- 1:24:31and one is present or one is I'm passing
- 1:24:33it from the runtime from my command line
- 1:24:36so which precedence or which value will
- 1:24:38be getting uh printed once I run and
- 1:24:41execute this particular task so the
- 1:24:43answer is if you pass anything from the
- 1:24:45command line or from the runtime which
- 1:24:47is present over here will'll get the
- 1:24:49Precedence so that's the priority of the
- 1:24:52variable if you pass anything from the
- 1:24:54command line then that variable value
- 1:24:56will always be used inside your n
- 1:24:59Playbook so let's run this and see this
- 1:25:01uh in action so I'll just head over to
- 1:25:03terminal and let me first copy this
- 1:25:05particular
- 1:25:07command go to terminal I'll create the
- 1:25:11screen and pest it over
- 1:25:14here and here you can see uh this is the
- 1:25:17value which got printed that is f world
- 1:25:19but here in the wars file the value was
- 1:25:22F so it will always override if you pass
- 1:25:25anything at a runtime then it will
- 1:25:27always override the values which is
- 1:25:29present uh inside your ncble Playbook or
- 1:25:31if you have created a variable inside
- 1:25:33your Wars file so runtime is always get
- 1:25:36the precedence over any other variable
- 1:25:39so that's the Precedence order I just
- 1:25:40wanted to show you inside this uh Anu
- 1:25:43Playbook all right so that's what I just
- 1:25:46wanted to show you into the today's
- 1:25:47session on anible variable but in the
- 1:25:49next session which is going to be a
- 1:25:51little bit short session because you are
- 1:25:53already familiar with the variables but
- 1:25:55in the next session we're going to talk
- 1:25:56about the environment variables and how
- 1:25:58to use those environment variable inside
- 1:26:00your anible clickbook so that's going to
- 1:26:02be the next session and after that we
- 1:26:04are just going to talk more about the if
- 1:26:06then else statement and how to use those
- 1:26:08if then else statement inside your
- 1:26:09anable play so stay tuned and see you
- 1:26:12into the next session of anible and if
- 1:26:14you're interested in any other devop
- 1:26:16topic like like terraform kubernetes
- 1:26:18then please go out and check my channel
- 1:26:20where I have uploaded those sessions so
- 1:26:22till then take care and bye-bye
- 1:26:25hello and welcome back like in the
- 1:26:27previous session we have talked about
- 1:26:29the anible variables but in this lab
- 1:26:32session we are going to talk about the
- 1:26:33environment variables now when we are
- 1:26:35talking about the environment variables
- 1:26:37then I'm talking about the path home and
- 1:26:40user so this is just an example of
- 1:26:42environment variables which are
- 1:26:44generally available onto the environment
- 1:26:46so anible Playbook allows you to update
- 1:26:49and use those environment variables when
- 1:26:51you are writing your own Playbook so
- 1:26:53with the help of anel you can set the
- 1:26:55custom environment variable which is
- 1:26:57needed for your anible playbook and
- 1:27:00those environment variables can be set
- 1:27:02at a task level or you can set it on
- 1:27:04that particular Global or the Playbook
- 1:27:06level all right so now I switch to my
- 1:27:08desktop uh let me zoom in over
- 1:27:11here and here this is the Playbook which
- 1:27:13I have created to explain the
- 1:27:15environment variable so first of all
- 1:27:17what we are going to do first of all we
- 1:27:18are just going to create this
- 1:27:19environment variable at very top level
- 1:27:22or anible Playbook level so that this
- 1:27:24environment variable which I have
- 1:27:26declared over here will be accessible
- 1:27:28for all the task which is mentioned
- 1:27:29inside my playbook second we are just
- 1:27:32going to create a one more environment
- 1:27:34variable which is present inside the
- 1:27:36task and the visibility and the scope of
- 1:27:38that environment variable is only within
- 1:27:41this particular task and this cannot be
- 1:27:43accessed outside of that particular task
- 1:27:46so that's these are the two use cases
- 1:27:48which we are going to see in this demo
- 1:27:50okay let me break this anible Playbook
- 1:27:52and first of all we'll start with like
- 1:27:54how to create an environment variable so
- 1:27:56at line number nine you will see a
- 1:27:57keyword or attribute that is named
- 1:27:59environment and below that you will find
- 1:28:02the line where I have written a variable
- 1:28:04name that is example and the value I
- 1:28:06have assigned over here is fuar so this
- 1:28:09example name is user defined name you
- 1:28:11can keep a environment variable name of
- 1:28:13your choice so here you can uh keep a
- 1:28:15one more variable name like a my V one
- 1:28:19and you can assign the value to it also
- 1:28:21so that will also work so I can put VAR
- 1:28:24varable
- 1:28:26value
- 1:28:29one so that also works so here you can
- 1:28:31create a multiple number of environment
- 1:28:33variable but what's the key thing over
- 1:28:36here is this environment variable like
- 1:28:38example and my wi one these two
- 1:28:41environment variables are available for
- 1:28:43all the task which I'm going to create
- 1:28:46or which I have already defined inside
- 1:28:48my playbook so these variables can be
- 1:28:50accessed throughout these all these
- 1:28:52tasks so that's the key benefit which
- 1:28:54you will get if you define the
- 1:28:55environment variable in this fashion now
- 1:28:58second thing like uh if you want to
- 1:29:00define a environment variable which is
- 1:29:02not Global but which is very specific to
- 1:29:05a particular
- 1:29:06task so over here in this section so
- 1:29:09here I have created a variable or a task
- 1:29:12uh sorry it's not variable it's a task
- 1:29:14so environment variable for only task
- 1:29:16level so here I have created again the
- 1:29:18same like I have used the keyword
- 1:29:20attribute that is environment and the
- 1:29:21variable name that is my task level
- 1:29:23variable
- 1:29:24and I have assigned the value that is
- 1:29:26hello world so now we have two
- 1:29:28environment variable maybe we can say 3
- 1:29:31environment variable example mayware one
- 1:29:34and then this is the third one which is
- 1:29:35very specific to that particular task
- 1:29:38and here what we are doing for each task
- 1:29:40we are printing the value so here you
- 1:29:41can see I'm just printing the value of
- 1:29:43example which is like a global
- 1:29:45environment variable and here I'm just
- 1:29:47trying to print the value which is like
- 1:29:49a task level environment variable which
- 1:29:51is this one and the third thing uh I
- 1:29:54just wanted to demonstrate like I just
- 1:29:56wanted to access I just wanted to access
- 1:29:58the both variable that is example which
- 1:30:01is this as well as this uh like a task
- 1:30:03level environment variable which is this
- 1:30:05one so ideally uh this particular task
- 1:30:08we should only get the value of this
- 1:30:10variable but not this one because this
- 1:30:13my task level variable is a task level
- 1:30:15uh environment variable and I cannot
- 1:30:18access it because it is outside of this
- 1:30:20part uh outside of the scope of that
- 1:30:22particular task so these are the three
- 1:30:25tasks which I have created uh let's
- 1:30:27switch over to terminal and run this
- 1:30:29playable all right so this is my
- 1:30:30terminal and this is the command which
- 1:30:32I'm just going to run but in case if you
- 1:30:34are wondering like where to find this
- 1:30:35command then I have created this readme
- 1:30:37file over here inside this particular
- 1:30:39project so from here you can just copy
- 1:30:41this particular command and this whole
- 1:30:43repository I'll post it onto my
- 1:30:45description section so you can clone
- 1:30:47this particular repository okay so
- 1:30:49coming back to my terminal which is over
- 1:30:51here so I'm just going to add one more
- 1:30:53flag for verbos that is V so that we can
- 1:30:55see the output of our task I mean to say
- 1:30:59uh if I open this one so we can see this
- 1:31:01output like a built-in command where I'm
- 1:31:03doing the EO so that's why I have added
- 1:31:05a verbos parameter over there you just
- 1:31:07simply need to execute
- 1:31:09it okay so let's uh Analyze This output
- 1:31:12task level so first we will start from
- 1:31:15this particular task the name of the
- 1:31:16task is environment bar at Playbook
- 1:31:18level and here we are doing the Eco of
- 1:31:20example so if you go to terminal once
- 1:31:23again so so yeah this is the task which
- 1:31:25we have executed and this is the output
- 1:31:27which we are getting that is fuar and if
- 1:31:30you check so yeah this is the fuar and
- 1:31:32we are able to access that environment
- 1:31:33variable inside that particular task and
- 1:31:36because this is a global or ncble level
- 1:31:40uh Playbook level variable all right now
- 1:31:43coming to the next task which is
- 1:31:44environment for only task level so here
- 1:31:47at the task level what we have done we
- 1:31:49have created this variable and the value
- 1:31:51is hello world and if you go back to
- 1:31:53terminal
- 1:31:54uh then you will see the output that is
- 1:31:56hello world so that's also correct
- 1:31:58that's also valid but this third task is
- 1:32:01bit interesting because here we have we
- 1:32:02are accessing the example as well as the
- 1:32:04previous uh this attribute uh this
- 1:32:07environment variable so ideally we
- 1:32:08should only get the value of example but
- 1:32:11not this one so let's open the terminal
- 1:32:14once again and here you can see the
- 1:32:16output so here you can see the output
- 1:32:18foar and that is this one this is the
- 1:32:21foar and which is right actually but on
- 1:32:24the other hand if you take a look then
- 1:32:26the value of this variable is not
- 1:32:27getting printed because that particular
- 1:32:29environment variable is outside the
- 1:32:31scope of that particular task so that's
- 1:32:34why I have created this third task to
- 1:32:36just to show you the difference between
- 1:32:38the task level environment variable and
- 1:32:40the Playbook level environment variables
- 1:32:42all right so this is how you're just
- 1:32:44going to create an environment variable
- 1:32:45inside your playbook and you can access
- 1:32:47those environment variable either at a
- 1:32:49task level or a Playbook level well this
- 1:32:52was a very small demo but this concept
- 1:32:54was really important because when you
- 1:32:56are going to write your anible playbook
- 1:32:59for your production application then you
- 1:33:01will need uh to use this environment
- 1:33:03variables quite a lot and you should be
- 1:33:05really careful like where you are
- 1:33:06defining your environment variable
- 1:33:08whether it's a task level or whether
- 1:33:10it's like a Playbook level so keep in
- 1:33:12mind those Concepts and try to use this
- 1:33:14environment variable in those fashion
- 1:33:17all right so that was all about the
- 1:33:18environment variable but in the next
- 1:33:19session of a anible series we are going
- 1:33:21to talk about the if then and else
- 1:33:23statement so stay tuned for the next
- 1:33:25episode and in the upcoming weeks I'm
- 1:33:27going to upload more uh similar session
- 1:33:30onto the anible Playbook and anible
- 1:33:32Series so stay tuned for that and if you
- 1:33:35are new to this channel then you can
- 1:33:37just subscribe to this channel where you
- 1:33:38will find the content on terraform
- 1:33:41Docker kubernetes and sible and there
- 1:33:43are many sessions which I have uploaded
- 1:33:45for a Helm chart also so just go and
- 1:33:48check those lab session if you're new to
- 1:33:50the DeVos so stay tuned for that and see
- 1:33:53you into the next next session till then
- 1:33:55take care and
- 1:33:56bye-bye hello there this is Rahul and
- 1:33:59welcome to the anible series in the
- 1:34:01ninth part of this series we will be
- 1:34:03talking about anible
- 1:34:06conditionals now the question comes like
- 1:34:08what is conditional in anible so if you
- 1:34:10are familiar with any programming
- 1:34:11languages then you might have used the
- 1:34:13if statement for evaluating any
- 1:34:15conditions similarly in anible we have a
- 1:34:18conditional which will help us to
- 1:34:20evaluate any condition and based on that
- 1:34:22condition we will be taking the next
- 1:34:23step or we will be executing the next
- 1:34:25sensible instructions here onto the
- 1:34:27screen you can see on the left hand side
- 1:34:29it's a traditional if condition with any
- 1:34:31other programming languages so where you
- 1:34:33specify if and inside that you specify a
- 1:34:35condition and after that you write a
- 1:34:37code which you want to execute based on
- 1:34:39that particular condition but in anible
- 1:34:42we actually don't have a if condition
- 1:34:44instead we have a when condition so
- 1:34:46whenever we need to put any condition
- 1:34:49then we are just going to use the when
- 1:34:51conditional inside your anible playbook
- 1:34:54in the beginning it might sound
- 1:34:56complicated but in actual it is really
- 1:34:58simple to implement a conditional using
- 1:35:00a when condition so here onto the screen
- 1:35:02if I scroll it down I have taken a very
- 1:35:04basic example to understand this van
- 1:35:06conditional so here this is my playbook
- 1:35:09where I'm just trying to install an
- 1:35:10Apache server onto my remote server but
- 1:35:13I want to install this Apache server
- 1:35:15based on one condition so here you can
- 1:35:17see this is the condition which I have
- 1:35:19specified using the V so here inside
- 1:35:22that condition you will see a flight
- 1:35:24that is install Apache flag so that's a
- 1:35:26Boolean flag which I have kept and if
- 1:35:28you see below over here so this is the
- 1:35:31value of that particular variable and
- 1:35:33here this value is bullan so based on
- 1:35:36true and false I'll be able to install
- 1:35:38that particular Apache so in variable
- 1:35:40file if you have kept the value true
- 1:35:42which you can see over here the value is
- 1:35:44true so in that case if whenever I'm
- 1:35:46just going to execute this particular
- 1:35:48Playbook I'm talking about this Playbook
- 1:35:49then it is going to install the Apache
- 1:35:51server but in case if this particular
- 1:35:53value this particular variable value is
- 1:35:55false then in that case our uh Apache
- 1:35:58server will not be installed using our
- 1:36:00NC Playbook so that's the simplest
- 1:36:03implementation uh which you can see over
- 1:36:05here using the V condition and don't
- 1:36:07worry we're just going to perform a demo
- 1:36:08after this uh where we are going to
- 1:36:10implement this when condition inside our
- 1:36:12anible
- 1:36:13Playbook all right so now you're a bit
- 1:36:15familiar with the when condition and in
- 1:36:17the previous example we have just seen
- 1:36:19one condition inside the van conditional
- 1:36:21block but now what if we can specify
- 1:36:24multiple conditions inside our when
- 1:36:27conditional block so here in this
- 1:36:29example and onto this screen you can see
- 1:36:31the example where I have taken the when
- 1:36:33block and inside that V block I have a
- 1:36:34specified multiple condition so this is
- 1:36:37going to be my first condition and this
- 1:36:38is going to be my second condition and
- 1:36:40if both conditions are true then after
- 1:36:43that this whole anible Playbook is going
- 1:36:45to execute and it is going to install
- 1:36:47anything or any task which you want to
- 1:36:49perform all right so that's a one way of
- 1:36:51specifying multiple condition inside
- 1:36:52your van block
- 1:36:54now I'm taking a one more example over
- 1:36:56here I will increase the font size over
- 1:36:58here so here you can use our traditional
- 1:37:01and operator so here again you can
- 1:37:03specify multiple condition but instead
- 1:37:05of putting the condition into the next
- 1:37:06line you can use the end operator and
- 1:37:08specify the condition in a single line
- 1:37:11so here you can see uh this is the first
- 1:37:13condition which I have specified over
- 1:37:14here and if I scroll it horizontally
- 1:37:16then this is the end condition which you
- 1:37:18can see so this is the end condition
- 1:37:19which is sitting in between and this is
- 1:37:22the second condition which I have
- 1:37:23specified so this is a more traditional
- 1:37:26way of specifying multiple condition
- 1:37:28inside our when conditioner so it's up
- 1:37:30to you which one you want to prefer and
- 1:37:32which one you want to use I personally
- 1:37:34like to prefer this previous one where
- 1:37:36we have like defined each condition into
- 1:37:38the next line so that it's more readable
- 1:37:41and more
- 1:37:43concise now moving to the next topic
- 1:37:45inside our conditional so here I'm just
- 1:37:47talking about putting a condition on a
- 1:37:49particular value and that value can be
- 1:37:52stored inside a variable so we can
- 1:37:54specify conditions based on the value of
- 1:37:57a particular variable so here onto the
- 1:37:59screen you can see uh this is the anible
- 1:38:01Playbook where we are registering a
- 1:38:03variable so this is uh a register
- 1:38:05keyword which is provided by anible and
- 1:38:07here we are just specifying a variable
- 1:38:09name that is test file content that's
- 1:38:11the variable name which I have created
- 1:38:13and inside that particular variable we
- 1:38:15are just going to store the value of
- 1:38:17this particular text file I'm just going
- 1:38:19to show everything into the demo but
- 1:38:21this is the text file uh which is
- 1:38:23present onto my remote server and
- 1:38:25whatever content present inside the text
- 1:38:26file I'm just going to store inside this
- 1:38:28particular variable so that's the first
- 1:38:31part of anible Playbook and what I'm
- 1:38:33just going to do I'm just going to put
- 1:38:34the condition on that particular
- 1:38:36variable so here in the next anible
- 1:38:39Playbook task you will see I'm putting a
- 1:38:41v block over here so if you can see over
- 1:38:43here this is the V and here I'm just
- 1:38:45specifying the condition on that
- 1:38:47particular variable so here you can see
- 1:38:49test file contain STD out you need to uh
- 1:38:52fet that particular value inside from
- 1:38:55inside the variable so that's why I'm
- 1:38:56just using STD out that's a standard
- 1:38:58output and after that I'm just putting a
- 1:39:00fine condition because I'm expecting a
- 1:39:03high content I have just uh it is just a
- 1:39:05manual text which I have put inside the
- 1:39:07text file so I'm expecting it will
- 1:39:08return high so I'm just trying to find
- 1:39:10that particular content and if this
- 1:39:12particular condition satisfied then I'll
- 1:39:14say yeah just execute this particular
- 1:39:17task so this is the condition which I
- 1:39:19have put over here so when this
- 1:39:21particular condition satisfied then I'm
- 1:39:22just going to print out the output of
- 1:39:24that particular variable so that's how
- 1:39:27you're just going to uh like register a
- 1:39:29variable assign some value to it and
- 1:39:31later on you're just going to evaluate
- 1:39:33that particular value based on the when
- 1:39:35conditional so this is how you can play
- 1:39:37around with the variables
- 1:39:39also all right moving to the next Topic
- 1:39:42in conditional so now I'm going to talk
- 1:39:44about the loops and you might be
- 1:39:45familiar with the for Loop or for each
- 1:39:47Loop in any other programming languages
- 1:39:49for example python Java go or any
- 1:39:52programming languages they must have
- 1:39:54some kind of a looping logic implemented
- 1:39:57inside those programming languages but
- 1:39:59here in anible we can also use the
- 1:40:00looping and here I have just taken a
- 1:40:02very simple example where I have created
- 1:40:05uh like a condition uh based on the
- 1:40:07value of that particular uh list
- 1:40:09actually so here I'm just first of all
- 1:40:11going to define the loop that's the
- 1:40:13keyword from anible and here I'm just
- 1:40:15going to specify the array of numbers
- 1:40:18and based on certain condition I'm just
- 1:40:20going to like print uh the value of
- 1:40:22those uh variables which is present
- 1:40:25inside my array but the condition is I'm
- 1:40:27just going to print the value which are
- 1:40:29only greater than five so here I have a
- 1:40:32specified that condition over here so
- 1:40:34when this Loop is getting executed then
- 1:40:36this when condition will be evaluated
- 1:40:39I'm talking about this one condition and
- 1:40:41when this condition is evaluated then we
- 1:40:43are just going to evaluate whether that
- 1:40:44value is lesser than five or greater
- 1:40:46than five if it's greater than five then
- 1:40:48we are just going to do the print of
- 1:40:50that particular value so this is how you
- 1:40:52also can use use the when conditional
- 1:40:54inside your
- 1:40:56loops and the last topic before the demo
- 1:40:59is anible facts so we can use the
- 1:41:03condition the van condition on anible
- 1:41:05facts also so anible facts are something
- 1:41:07which is like inbuilt so if you're
- 1:41:09trying to run an anible Playbook on a
- 1:41:11remote machine then anible facts will
- 1:41:14always hold the value of that particular
- 1:41:16remote machine and what does it mean by
- 1:41:18value I'm not referring to a single
- 1:41:19value but I'm referring here to the
- 1:41:21multiple values so it might contain what
- 1:41:23the remote IP what's the operating
- 1:41:25system whether it's a sento whether it's
- 1:41:27a daan and what's the version it is
- 1:41:29running what's the CPU type what's the
- 1:41:31chip type so all these information which
- 1:41:33is like a metadata about that particular
- 1:41:35machine will be stored automatically
- 1:41:37inside the anible facts and using those
- 1:41:40in insensible facts which you can see I
- 1:41:42have just taken one example of this
- 1:41:43anible facts from the anible
- 1:41:45documentation so these are the facts you
- 1:41:47can capture for that particular remote
- 1:41:49machine and these uh particular
- 1:41:52variables like all IP addresses and uh
- 1:41:55also there are like ncble app armor so
- 1:41:58these are the facts which is readily
- 1:42:00available to you so you can put the
- 1:42:02condition on these particular anible
- 1:42:04facts also so here I have taken one
- 1:42:06example which you can see over here so
- 1:42:08here I I have just specified the V
- 1:42:10condition but this V condition is
- 1:42:11running on the anible facts this is the
- 1:42:14keyword and what anible facts I just
- 1:42:16wanted to evaluate so I just want to
- 1:42:18evaluate the OS family so what's the OS
- 1:42:20family of the remote machine so that
- 1:42:23that's the when condition I'm just going
- 1:42:24to evaluate since I'm running the uban 2
- 1:42:26and which is a devian base so I just I'm
- 1:42:28expecting the value is to be devian so
- 1:42:32these conditionals you can put onto the
- 1:42:34anible facts also so this is just a One
- 1:42:37More Concept which is left inside the
- 1:42:39conditional which is I just wanted to
- 1:42:40show you before the
- 1:42:42demo all right so moving to my intellig
- 1:42:45where I have written my anible playbook
- 1:42:47and on the left hand side you will see
- 1:42:48this is the project which I have created
- 1:42:50onto my GitHub repository I'll put the
- 1:42:52link of this particular GitHub
- 1:42:53repository into the description section
- 1:42:55so feel free to clone that particular
- 1:42:57repository so here this is uh the
- 1:43:00project structure and here I have
- 1:43:01created a part nine and inside that you
- 1:43:03will find a task and variables file and
- 1:43:06also the main Playbook and after that
- 1:43:08you will find a read me file so you can
- 1:43:10just simply copy this anible Playbook
- 1:43:12command from here to run this particular
- 1:43:14anal Playbook but in the host file you
- 1:43:16need to uh update the remote host IP so
- 1:43:20here I'm just using my AWS ec2 instance
- 1:43:23which is running onto the uh AWS Cloud
- 1:43:26so that's why I'm using it over here but
- 1:43:28instead you can use your own remote
- 1:43:30machine all right so that's all about
- 1:43:32the practicalities of this particular
- 1:43:35project but let's go back to the uh
- 1:43:37actual code where I have specified these
- 1:43:40conditionals so here this is the first
- 1:43:43block where I have specified install
- 1:43:44Apache web server based on the condition
- 1:43:47that is install Apache flag and that's a
- 1:43:49Boolean variable so let's check the
- 1:43:51value of that particular V buan variable
- 1:43:53and that is true so that means if I'm
- 1:43:56going to execute this particular anible
- 1:43:58Playbook then it is going to install the
- 1:43:59Apache server onto my remote machine so
- 1:44:02that's the first use case what I I'm
- 1:44:05going to do I'm just going to remove
- 1:44:06rest of the details so that we only run
- 1:44:09the required one I'm just going to save
- 1:44:11this thing go to the readme file over
- 1:44:13here copy this anible Playbook command
- 1:44:16open the
- 1:44:18terminal and here into the terminal uh
- 1:44:20you can just simply paste that
- 1:44:21particular command for executing your an
- 1:44:24label uh let me check the folder where I
- 1:44:27am in so I need to switch to see uh part
- 1:44:30n I'll clear the screen and just check
- 1:44:33yeah I'm inside my directory that is
- 1:44:35part mine and after that you can just
- 1:44:37simply run that command this is the
- 1:44:39command which I'm just going to execute
- 1:44:41simply execute it all right so here you
- 1:44:43can see uh that it has successfully
- 1:44:46executed the install Apache web server
- 1:44:49so that means based on that particular
- 1:44:51condition which is true right now it is
- 1:44:52able B to install the Apache but I'm
- 1:44:55just going to do one more thing uh what
- 1:44:56I'm just going to do I'm just going to
- 1:44:58update the value and set it to false so
- 1:45:03once we set anything or this particular
- 1:45:05condition to false then it is going to
- 1:45:06skip that particular installation step
- 1:45:09so I'll just go back to terminal once
- 1:45:11again and I'm just going to re-execute
- 1:45:13although we have installed Apache but
- 1:45:15our main intention is not to install
- 1:45:17Apache button Ste we just wanted to
- 1:45:18check the condition so here you can see
- 1:45:20it has skipped that particular step so
- 1:45:23what does it mean so that means that
- 1:45:24based on that particular condition it is
- 1:45:26evaluating whether it whether it has to
- 1:45:29execute that tensible task or not so in
- 1:45:31that case when we have set the value to
- 1:45:33false it has just skipped that
- 1:45:35particular task now in the next example
- 1:45:37we are just going to evaluate multiple
- 1:45:39condition based on the anible facts so
- 1:45:42here onto the screen you can see this is
- 1:45:43the when condition which I have
- 1:45:45specified but inside that V condition I
- 1:45:47have a specified couple of more
- 1:45:48condition and these conditions are just
- 1:45:51simply checking the anible facts so the
- 1:45:53facts where I'm talking about is the OS
- 1:45:55family so what kind of os family the
- 1:45:57remote machine belongs to and since it's
- 1:45:59UB to best so that's a Dean so that's
- 1:46:01the first check secondly what's the
- 1:46:03distribution major version so what's the
- 1:46:05OS version of that Linux machine so
- 1:46:07which is 20 so that I already know it so
- 1:46:10that's why I have put this particular
- 1:46:11condition so again let's go back to
- 1:46:13terminal over here I'm just going to
- 1:46:15clear the previous
- 1:46:16output and I'm just going to Simply run
- 1:46:18the N Playbook and here you can see uh
- 1:46:22since the previous value we have set for
- 1:46:23install Apache to false that's why it
- 1:46:25has been skied but this task combined
- 1:46:28condition using anel has executed
- 1:46:30successfully and if we check over here
- 1:46:32then what we are doing over here when
- 1:46:34this particular both the conditions are
- 1:46:36passed then we are just printing the
- 1:46:38kernel version into the console so here
- 1:46:41just go back to terminal and check so
- 1:46:43here you can see the anible kernel
- 1:46:45version which is 40 Ubuntu SMP and the
- 1:46:48time St so which has evaluated that
- 1:46:51particular condition has evalu ated that
- 1:46:53condition properly and our both the
- 1:46:55facts anible facts are true and we have
- 1:46:57got the output over here okay moving
- 1:46:59back to my anible playbook so here I
- 1:47:01have specified the same condition using
- 1:47:03the and condition over here so you can
- 1:47:05see again the anle facts I'm checking
- 1:47:08over here are same I'm just still
- 1:47:10checking the Debian as well as I'm just
- 1:47:12checking the version which is what is
- 1:47:14the major version and that has to be
- 1:47:15greater than 20 so that's the only
- 1:47:17change which I have did from the
- 1:47:19previous condition where I was checking
- 1:47:20for exact 20 version but here I'm just
- 1:47:22checking a version which is greater than
- 1:47:24or equal to 20 but rest of the
- 1:47:26conditions are same so I just wanted to
- 1:47:28demonstrate you that's why I have put
- 1:47:29this particular task over here so onto
- 1:47:32the terminal if you go back I'll clear
- 1:47:34the screen once again and you can just
- 1:47:36simply run the N playable and here you
- 1:47:39can see the setting complex condition
- 1:47:40that was my task name and we can verify
- 1:47:42it over here so setting complex
- 1:47:44condition and here we are having two
- 1:47:45condition this is the first one and this
- 1:47:47is the second one and onto the terminal
- 1:47:50you will see the output the anible
- 1:47:52kernel version which which is 40 so
- 1:47:54that's how you can put multiple
- 1:47:55conditions inside your anible task
- 1:47:57within your anible playbook all right
- 1:47:59now moving to the next example where I
- 1:48:00have shown or where I have already
- 1:48:02explained like how to register a
- 1:48:03variable and then assign a value to that
- 1:48:06particular variable and then evaluate
- 1:48:08that particular variable so here I'm
- 1:48:10just first of all going to register a
- 1:48:11variable with the name test file content
- 1:48:14and after that I'm just going to
- 1:48:15evaluate the value of that particular
- 1:48:17variable and the value I'm expecting
- 1:48:19over here is just a two character which
- 1:48:21is high so I'm expecting a file to be
- 1:48:24present at that particular location so
- 1:48:26I'm just going to go to my terminal and
- 1:48:28this is my remote machine I'll just
- 1:48:30clear the screen just check the path
- 1:48:32that I'm under home/ to just do the ls
- 1:48:36to verify the file there is a file test
- 1:48:37file.txt and you can just do the cat to
- 1:48:40verify the content and here you can see
- 1:48:42the content of file is just a simple two
- 1:48:45character which is high so I'm just
- 1:48:47going to fetch this particular value of
- 1:48:49a file inside the variable and then I'm
- 1:48:51just going to evaluate the condition so
- 1:48:53this is the command uh to do the cat and
- 1:48:56it will register into this variable and
- 1:48:57then we are just going to do the
- 1:48:59standard out and then compare the value
- 1:49:02all right so let's go back and here
- 1:49:04after the comparing the value this will
- 1:49:06debug and print the value of that
- 1:49:08particular variable so that we know that
- 1:49:10condition has been evaluated so let's go
- 1:49:13back to terminal and uh I'll clear the
- 1:49:15screen over here and simply execute the
- 1:49:18play and here you can see first of all
- 1:49:20it has registered the variable so it has
- 1:49:22fatch the value of that particular file
- 1:49:25and after that it has evaluated that
- 1:49:26condition and print the value of that
- 1:49:28particular variable so which you can see
- 1:49:30which is high so here uh this is the
- 1:49:33output which we have just verified all
- 1:49:35right now moving to the next example
- 1:49:37where I have shown the loop so here I
- 1:49:39have a specified the array so where I'm
- 1:49:41just going to Loop so that array
- 1:49:42contains the value 0 2 4 6 8 and 10 but
- 1:49:45the condition which I'm putting over
- 1:49:47here is item should be greater than five
- 1:49:49and once the value is greater than five
- 1:49:50then I'm just going to print the value
- 1:49:52of that particular item so that's the
- 1:49:54simplest uh like a for Loop or The Loop
- 1:49:57which I have implemented over here so
- 1:49:58I'm just going to head over to terminal
- 1:50:00I'm just going to clear the screen and
- 1:50:02run the
- 1:50:03Playbook and here you can see the output
- 1:50:05onto the terminal but if you take a look
- 1:50:08carefully then you need to check which
- 1:50:10part has been skipped and which part has
- 1:50:12been changed so this skipped part which
- 1:50:15means we we are we are not printing 0 2
- 1:50:18and four I mean these values are script
- 1:50:20because those were lesser than five but
- 1:50:22the values which are greater than five
- 1:50:24has been uh printed over here with a
- 1:50:26changed uh like highlighted so these are
- 1:50:29the values which has been entertained
- 1:50:31and which has been printed using that
- 1:50:33for Loop so that's how you're just going
- 1:50:35to iterate over a loop using the
- 1:50:37conditional and moving to the last part
- 1:50:39where I was talking about the anible
- 1:50:41facts and you can put multiple anible
- 1:50:43facts inside your when conditioner so
- 1:50:45here I have just taken a fact uh the
- 1:50:47anible fact is a keyword over here and
- 1:50:49the fact I'm verifying is the operating
- 1:50:51system family and I'm expecting value to
- 1:50:53be Debian if it's Debian then I'm just
- 1:50:55going to print the distribution name of
- 1:50:57that particular anmol F so go to
- 1:51:00terminal clear the screen uh screen is
- 1:51:02already cleared so I'm just going to
- 1:51:04execute the
- 1:51:06Playbook and here you can see uh anible
- 1:51:08distribution which is one two so that's
- 1:51:10how I'm just going to evaluate uh my
- 1:51:13anible facts and after evaluating inside
- 1:51:15the van condition I'm just going to
- 1:51:16print the web all right so that
- 1:51:18concludes our ninth lab session on
- 1:51:20anible and till now we have covered
- 1:51:22fourth chapter which you can see over
- 1:51:23here from the content page and in the
- 1:51:25next chapter we'll be talking about the
- 1:51:27roles and the task associated with your
- 1:51:29Anvil Playbook and in that session we'll
- 1:51:32be talking about how to import the roles
- 1:51:34how to import the different task inside
- 1:51:36your anible playbook so stay tuned for
- 1:51:38that and if you interested into the
- 1:51:40similar content on devops where I talk
- 1:51:42about terraform kubernetes stalker
- 1:51:44containers and Helm chart then please
- 1:51:46consider subscribing to this channel
- 1:51:47because there are similar session I have
- 1:51:49planned in the future and upcoming
- 1:51:51months which you will see onto this
- 1:51:52channel so till then take care and
- 1:51:56bye-bye hello there this is Rahul and
- 1:51:58welcome to the sensible series and in
- 1:52:00this 10th part we will be taking a look
- 1:52:02onto the task and the
- 1:52:05roles the idea of this session is to
- 1:52:07understand what are roles and how to
- 1:52:08create multiple task inside your anible
- 1:52:10playbook so in this session we'll first
- 1:52:12try to look and understand what is Task
- 1:52:14and the rules and after that we are just
- 1:52:16going to perform a demo to understand
- 1:52:18both task and the
- 1:52:20roles all right so to begin with it's
- 1:52:23really important for us to understand
- 1:52:25the structure of our roles and the task
- 1:52:27so here onto the screen if you'll see
- 1:52:29this is the screenshot which I have
- 1:52:30taken from my projects and into this
- 1:52:32screenshot you will see there is a roles
- 1:52:34so this is the roles which I have
- 1:52:35created this is the standard roles
- 1:52:37directory where we are going to define
- 1:52:38the roles and here I have created couple
- 1:52:40of roles so this is the first one and
- 1:52:42this is the second one so the name of
- 1:52:44the first role is custom role because I
- 1:52:45just wanted to create my own custom Ro
- 1:52:47but here in the second role if you'll
- 1:52:49see there is a unique name that is
- 1:52:51install Apache so that dictates like the
- 1:52:53second role is going to install the
- 1:52:55Apache so whenever you're working with
- 1:52:57an anible Playbook and you need to
- 1:52:58create a multiple task then what you're
- 1:53:00going to do first of all you're just
- 1:53:01going to go inside your roles directory
- 1:53:04and inside that you're just going to
- 1:53:05create the roles directories inside
- 1:53:08those now once you created those roles
- 1:53:11inside your roles directories now it's
- 1:53:13time for you to include those Ro inside
- 1:53:15your main anible Playbook so here the
- 1:53:17main anible Playbook is this one which
- 1:53:19is anible import roles Playbook yml so
- 1:53:22that is going to be my main Playbook so
- 1:53:24you need to include those roles inside
- 1:53:26that main Playbook so once you execute
- 1:53:28that particular main Playbook then it is
- 1:53:29going to execute those roles also so if
- 1:53:32you scroll down further then I have
- 1:53:34taken one more screenshot that is from
- 1:53:36my main anible Playbook so here you will
- 1:53:38see this is the first role which I have
- 1:53:40included and here this is the second
- 1:53:42role which I have included so once I'll
- 1:53:44execute this my main Playbook then it is
- 1:53:46going to execute first the custom role
- 1:53:48and then it is going to execute my
- 1:53:49second role which is install
- 1:53:51Apache
- 1:53:53all right so now we have taken a look
- 1:53:54onto the project structure of our roles
- 1:53:56and how to include those role inside
- 1:53:58your main anible
- 1:54:00Playbook let's talk about the task and
- 1:54:02how to create those task within those
- 1:54:04roles so if you take a look over here
- 1:54:06into the custom Ro and the install
- 1:54:07Apache role we have created a task
- 1:54:09directory so that's a standard practice
- 1:54:11which you need to follow while creating
- 1:54:12the task so if you expand that
- 1:54:14particular directory the task directory
- 1:54:15then you will find a main. yml so that's
- 1:54:18again you need to follow this standard
- 1:54:19practice of creating a main. yml within
- 1:54:21that particular task because in that
- 1:54:23main. yml you're just going to define
- 1:54:25the task for that particular role so
- 1:54:28here you will find the main. yml and
- 1:54:29also for install Apache you will also
- 1:54:31find a main. yml so those are the
- 1:54:33standard practice which you need to keep
- 1:54:34in mind now let's open the main. yml of
- 1:54:36one of the role and see what's present
- 1:54:38inside those so let's take a very simple
- 1:54:40one that is install Apache Ro and there
- 1:54:42is one main. yml present inside it so if
- 1:54:44you're going to open that particular
- 1:54:46main. yml then you will find the small
- 1:54:47small task that is first task is to
- 1:54:49install the Apache and the second task
- 1:54:51is to start the Apache server so that's
- 1:54:53the task which you have defined into
- 1:54:55that particular role and these
- 1:54:57particular task are associated with this
- 1:54:59particular install Apache role so once
- 1:55:01you include that particular role over
- 1:55:03here that is install Apache then it is
- 1:55:05going to what it's going to do it is
- 1:55:07first going to install the Apache and
- 1:55:08then it is going to start the Apache
- 1:55:12service let's take one more use case
- 1:55:14where we are going to create a subtask
- 1:55:16within the task so here in the custom Ro
- 1:55:18what I have done I have created a main.
- 1:55:20yml but that main. yml is still
- 1:55:22dependent on the subtasks so here there
- 1:55:25are a couple of tasks which I have
- 1:55:26defined that is messages. yml and that
- 1:55:28is packages. yml so these are the
- 1:55:30further subtask which I want to execute
- 1:55:32when I'm executing this particular
- 1:55:34anible Playbook so inside the main. yml
- 1:55:37you first of all you will see I have
- 1:55:38included or I have imported the package.
- 1:55:41yml that is package task and after that
- 1:55:43I have also imported the message. yml
- 1:55:45that is my message task and after that
- 1:55:48I'm just writing one my task which is to
- 1:55:51start the Eng genic Serv
- 1:55:52so let's take a look into the packages.
- 1:55:54yml first of all so if you open this one
- 1:55:56then what it's going to do it is just
- 1:55:57going to install some packages it is
- 1:55:59going to install enginex it is going to
- 1:56:01install G and it is going to install
- 1:56:03curve so that's the package. yml and it
- 1:56:05is a subtask present within the custom
- 1:56:08role and after that we need to include
- 1:56:10that into our main. yml all right so
- 1:56:12that's our packages. yml the second
- 1:56:14thing is the message. yml which I have
- 1:56:16already included or imported as a task
- 1:56:18so here what I'm doing simply I'm just
- 1:56:20copying uh the content of our uh like a
- 1:56:23HTML file which is present for Engen
- 1:56:26server and after that I'm just including
- 1:56:28it over here into the message. yml and
- 1:56:31finally we are just in restarting or
- 1:56:33starting our engine service onto my UB
- 1:56:35Tu machine so that's how you're just
- 1:56:37going to create a multiple subtask
- 1:56:39within that uh particular custom role
- 1:56:41and it can depend uh of course the name
- 1:56:43can be differ in your case but once you
- 1:56:46create those role then in that role you
- 1:56:47can create a subtask also and you can
- 1:56:49import those task within your main
- 1:56:53yml all right let's run this Playbook to
- 1:56:55verify the task and the roles which we
- 1:56:57have created so what you need to do you
- 1:56:59just need to go to the readme file and
- 1:57:00here you will find the Run Playbook
- 1:57:02instruction so you simply need to copy
- 1:57:03this command so it's basically doing uh
- 1:57:05it's just running this Nel import Ro
- 1:57:08Playbook and from the host and the host
- 1:57:09I have already defined over here in the
- 1:57:11ncble import Ro and the host so that's
- 1:57:13where you will find the host definition
- 1:57:15okay so I'm just going to open the
- 1:57:17terminal over here and I'm just going to
- 1:57:18P the command and hit enter so it should
- 1:57:20execute and it should include all those
- 1:57:22roles which we have created and it will
- 1:57:24execute all those tasks so let's see
- 1:57:26over here okay so here you can see uh if
- 1:57:29you go one by one so here we have first
- 1:57:31of all installed the package from the
- 1:57:33custom role so that's the first thing
- 1:57:34which we have did from the custom Ro we
- 1:57:36have set the message file which we have
- 1:57:37also seen then after that we are just
- 1:57:39restarting the engine server so that's
- 1:57:41where uh the three task which has been
- 1:57:43performed within the custom Ro now
- 1:57:45coming to uh the second part where we
- 1:57:47are just going to install the Apache
- 1:57:48which is our second role so here first
- 1:57:51of all we are just installing the aache
- 1:57:52then we are updating the configuration
- 1:57:54of Apache and then finally we are
- 1:57:55starting the Apache so that's how you're
- 1:57:57just going to execute your anible
- 1:57:59playbook which is includes multiple
- 1:58:01roles and in those roles we can have
- 1:58:02multiple tasks so that was all about the
- 1:58:04roles and task in anible and till now we
- 1:58:07have completed five chapters and uh in
- 1:58:09the next chapter we'll be talking about
- 1:58:10the templating in anible so where we
- 1:58:12will be covering the topics like a
- 1:58:14ginger templates I'll be taking a one
- 1:58:15example of a ginger template and it will
- 1:58:17help you to understand like how you can
- 1:58:19create the ginger template so stay tuned
- 1:58:21for that and if you're interested into
- 1:58:22the similar content on a devops then
- 1:58:24please considering subscribing to this
- 1:58:25channel so see you into the next session
- 1:58:27of anible and devops till then take care
- 1:58:28and
- 1:58:30bye-bye the objective of this session is
- 1:58:32to understand what is Ginger 2 template
- 1:58:34in anible and how to use the Ginger 2
- 1:58:36template for your anible
- 1:58:39playbooks before we jump to the demo
- 1:58:41let's try to understand like what is
- 1:58:43Ginger 2 template so as you can see onto
- 1:58:45the screen I have listed two benefits of
- 1:58:47ginger 2 template the first one is the
- 1:58:49dynamic configuration and the second one
- 1:58:51is the Dynamic script so whenever you
- 1:58:53want to use the dynamic configuration or
- 1:58:56dynamic script then you should rely on
- 1:58:58the Ginger 2 template I know it sounds
- 1:59:00complicated but the next example which
- 1:59:02I'm just going to take it is going to
- 1:59:04explain the Ginger 2 template in a very
- 1:59:06simple
- 1:59:07manner all right so then let's start
- 1:59:09with like how you can create a ginger to
- 1:59:11template so onto the screen you can see
- 1:59:13I have created my Ginger 2 template with
- 1:59:15the name like my config do J2 so any
- 1:59:19ginger2 template which you are creating
- 1:59:21inside your ible project that should end
- 1:59:23with the extension file name that is J2
- 1:59:27that is Ginger 2 template and you can
- 1:59:29Define any name for your Ginger 2
- 1:59:31template so here I have kept the name as
- 1:59:33a my config but in your case you can
- 1:59:35keep any name of your
- 1:59:37choice now once you have defined your
- 1:59:39Ginger 2 templates then I'm assuming
- 1:59:41your Ginger 2 templates is empty but
- 1:59:44here I have just taken a one screenshot
- 1:59:45and don't worry we are just going to
- 1:59:47take a demo and where I'm going to show
- 1:59:48you the complete configuration also but
- 1:59:51here onto the the screen if you will see
- 1:59:53this is the configuration of my one of
- 1:59:55the HTTP server and This Server here I'm
- 1:59:57just trying to put the dynamic value for
- 2:00:00Server Port which you can see over here
- 2:00:02which I have already highlighted so
- 2:00:04whenever you're working with the Ginger
- 2:00:062 template then you need to provide a
- 2:00:08interpolation so here the interpolation
- 2:00:10starts with the double curly braces on
- 2:00:12the left side and double curly braces on
- 2:00:15the right side and between those you
- 2:00:17need to put the variable which is a
- 2:00:19dynamic value which you will be
- 2:00:21providing in from your anible playbook
- 2:00:24so that's the first rule for using the
- 2:00:27Ginger 2
- 2:00:28template all right so now you know like
- 2:00:30how to create your Ginger 2 template
- 2:00:32with the J2 extension and how to create
- 2:00:34your interpolation and assign some
- 2:00:37variable inside those interpolation the
- 2:00:39next thing which I'm just going to talk
- 2:00:41about is how to call your gingu template
- 2:00:43inside your anible playbook and how how
- 2:00:46to pass the variable value which you are
- 2:00:48using inside your interpolation so the
- 2:00:51first thing which we are going to take a
- 2:00:52look is like how to call your Ginger 2
- 2:00:54template so as you can see this is the
- 2:00:56screenshot which I have taken and here
- 2:00:58first of all you need to use the keyword
- 2:01:00which is template so that anible
- 2:01:03Playbook know that you are just going to
- 2:01:05use the Ginger 2 template after that you
- 2:01:08need to specify the file name along with
- 2:01:10the path since this sensible Playbook
- 2:01:13and ginger to template are presented the
- 2:01:15same directory that's why I have just
- 2:01:17specified the name of that Ginger 2
- 2:01:19template because that's present in the
- 2:01:21same directory third thing which is
- 2:01:24really important is like you need to
- 2:01:26pass the value to that particular
- 2:01:28variable and in our case the variable is
- 2:01:30server Port so here you need to use the
- 2:01:33vars keyword inside your anible playbook
- 2:01:35so that it knows that you are just
- 2:01:37passing the variable and after that you
- 2:01:39need to assign the value whatever you
- 2:01:41want to assign to it so these These are
- 2:01:44the key principles when you're are using
- 2:01:46the gingu template so first of all you
- 2:01:48need to use the template keyword after
- 2:01:50that you need to specify the ninja to
- 2:01:52template file name along with the
- 2:01:54correct path and after that you need to
- 2:01:56use the wars keyword and then you can
- 2:01:58just specify the variable value which
- 2:02:00you are trying to use inside your
- 2:02:02interpolation so in that case this is
- 2:02:04our server uncore port and that is the
- 2:02:07value which is
- 2:02:09480 let's start with the demo and first
- 2:02:11of all we are just going to take a look
- 2:02:13onto the project structure and where we
- 2:02:15have defined our Ginger 2 template so
- 2:02:18here onto the screen you can see this is
- 2:02:19the part 11 anible Ginger 2 template
- 2:02:22that's the directory and here I have
- 2:02:24created a roles directory and don't
- 2:02:26worry this whole project is available
- 2:02:28onto my GitHub repository so you can
- 2:02:30find the link of my GitHub repository
- 2:02:32into the description section and here
- 2:02:35into the roles directory I have created
- 2:02:36one rule that is install Light httpd
- 2:02:39that's the one more server it's simple
- 2:02:41HTTP server and here inside the task I
- 2:02:45have created a main.yml but along with
- 2:02:47that I have a my config do J2 that's my
- 2:02:50Ginger 2 template and and remember I'm
- 2:02:52just going to use this gingu template
- 2:02:54inside the main. yml that's why I have
- 2:02:56kept it over there but in case if you
- 2:02:58have kept that particular Ginger 2
- 2:03:00template in some other directory then
- 2:03:02you need to put the correct path when
- 2:03:04using your Ginger 2 template all right
- 2:03:07that's that's something related to how
- 2:03:09to include your Ginger 2 template but if
- 2:03:11you take a look onto This Ginger 2
- 2:03:13template then here at line number 14
- 2:03:15this is the uh variable value which I'm
- 2:03:18passing dynamically so here onto the
- 2:03:21screen you can see this is the
- 2:03:22interpolation syntax which is available
- 2:03:24here on both left hand side and right
- 2:03:26hand side and here is the value of that
- 2:03:28particular variable which we will be
- 2:03:30passing when we are running the anible
- 2:03:31label let's take a look onto the main.
- 2:03:34yml and how to include our gingu
- 2:03:36template so just double click onto this
- 2:03:38main. yml and here you can see at line
- 2:03:41number 11 that's the source directory
- 2:03:43and where I'm just going to specify my
- 2:03:45ginger2 template file name so here I
- 2:03:48have a specified that is my config do J2
- 2:03:51and remember always keep this Source
- 2:03:53directory inside the template tag so
- 2:03:56that's the key thing when you when you
- 2:03:58are using the Ginger 2 template all
- 2:04:00right now the next thing which you need
- 2:04:02to do over here is to define the vars
- 2:04:04and in the vars you need to specify what
- 2:04:07variable you're passing inside your
- 2:04:09gingu template so here I'm specifying
- 2:04:11server undor port and the value is ET
- 2:04:14and which you can see over here into the
- 2:04:15gingu template which is server P so
- 2:04:18that's how I'm just going to include my
- 2:04:21Ginger temp template and I'm just going
- 2:04:22to assign some value or passing some
- 2:04:24value to the server Cod variable all
- 2:04:27right so that's all about the ginger to
- 2:04:29template and how to include that Ginger
- 2:04:31to template inside your anible playbook
- 2:04:33I I would like to explain my anible
- 2:04:35playbook and what we are going to
- 2:04:36achieve with that anible Playbook so
- 2:04:39here I'm just going to install Light
- 2:04:40httpd web server onto my Linux machine
- 2:04:44so that's the first task which I'm just
- 2:04:46going to do secondly here in the uh
- 2:04:49second task I'm just creating a
- 2:04:51configuration this is an httpd conf or
- 2:04:54like a server configuration which I'm
- 2:04:56planning to replace with my custom
- 2:04:59configuration and my custom
- 2:05:01configuration I would like to start my
- 2:05:03server on a port R so that's why I'm
- 2:05:05just going to replace this particular
- 2:05:07file this light httpd con which is
- 2:05:10present on Etc and /l httpd directory so
- 2:05:15I would like to replace this particular
- 2:05:16file which is present over there and I
- 2:05:18would like to replace this file with my
- 2:05:20config dog 2 which is my ging 2 template
- 2:05:24and here I'm just going to start finally
- 2:05:26my light httpd server let's run this
- 2:05:29Playbook and verify our Ginger 2
- 2:05:31template whether it's working or not so
- 2:05:33what you need to do you just need to
- 2:05:34head over to readme file and here I have
- 2:05:36written the command to execute this
- 2:05:38particular anible Playbook so I'm just
- 2:05:40going to copy this command go to
- 2:05:42terminal and paste this
- 2:05:45command so as you can see over here our
- 2:05:48task has just finished so here I have
- 2:05:50installed the light HTT TP web server
- 2:05:52after that we have created our own
- 2:05:55custom configuration for that server and
- 2:05:57then finally we have started our server
- 2:06:00so what I'm going to do next I'm just
- 2:06:01going to SSH into my server and I'm just
- 2:06:04going to verify my uh server
- 2:06:06configuration whether we have properly
- 2:06:09replaced those server configuration with
- 2:06:11my Ginger 2 template or not so this is
- 2:06:13my terminal and I'm just going to do I'm
- 2:06:15just going to SSH into my server uh
- 2:06:17which is my ec2 instance running on AWS
- 2:06:20simply hit enter
- 2:06:22and here I can uh see that I have logged
- 2:06:24in into my uh Linux server I'm just
- 2:06:26going to clear the screen and I'm just
- 2:06:28going to run the cat command to go to
- 2:06:30the ETC light HTTP and then I'm just
- 2:06:33going to view the con
- 2:06:36file and if we scroll up then you can
- 2:06:39see this is the server port and the
- 2:06:40value which I have assigned over here is
- 2:06:4280 so that's how we we are just able to
- 2:06:45replace our custom configuration for our
- 2:06:48server so that's a one place I have
- 2:06:50modified but you can use this Ginger to
- 2:06:53template concept to uh replace or put
- 2:06:55your custom configuration on a various
- 2:06:57places so it is not limited that you can
- 2:06:59only replace one configuration but you
- 2:07:02can replace more than one configuration
- 2:07:04so that you get more dynamicity and more
- 2:07:06custom configuration which you can put
- 2:07:08onto the servers so that's a one use
- 2:07:11case but you can use this concept to
- 2:07:13customize your configuration at certain
- 2:07:16extent so that will really help you to
- 2:07:18put your custom configuration and make
- 2:07:20your anle lebook more
- 2:07:23powerful all right so now you have seen
- 2:07:25the gingu template and how to use the
- 2:07:27gingu template to put your custom server
- 2:07:30configuration but I just want to take
- 2:07:32the same example and I just want to take
- 2:07:35it uh to the next level where I'm just
- 2:07:37going to change the port from 80 to 9090
- 2:07:40so why I'm doing this because you can
- 2:07:42use the same n Playbook and instead of
- 2:07:44running on a port 80 you can change the
- 2:07:46port to run it on a different port but
- 2:07:48that's not an ideal scenario but it can
- 2:07:51happen happen in future that you want to
- 2:07:52change some of your configuration and
- 2:07:54instead of running a server on a
- 2:07:56particular Port you want to change to
- 2:07:58run that Port that server onto different
- 2:08:00port so that's a hypothetical scenario
- 2:08:03but that's not in actual real use cases
- 2:08:05but something similar can happen into
- 2:08:07your own configuration also so what I'll
- 2:08:10do over here so instead of running it on
- 2:08:11a 80 I'm just going to change it to run
- 2:08:13it on a
- 2:08:149090 so with the help of this anible
- 2:08:18Playbook and Ginger 2 template you can
- 2:08:19simply update your anible play and pass
- 2:08:22a new value to your server configuration
- 2:08:25so here I'm just passing the value 9090
- 2:08:28I'll just save this changes and I'll
- 2:08:30head over to my
- 2:08:32terminal uh go to my ncble playbook I'm
- 2:08:35just going to clear the screen and rerun
- 2:08:37the playable so this time what it is
- 2:08:39going to do it is just going to update
- 2:08:41the server configuration and it is going
- 2:08:43to start my same server on a different
- 2:08:46port which is 9090 so here you can see
- 2:08:49uh it has changed the configuration and
- 2:08:51you can see the color has changed over
- 2:08:53here which means our server
- 2:08:55configuration has been changed and what
- 2:08:58we can do we can again go back to the
- 2:09:00another uh terminal over here where we
- 2:09:02have already logged in I'm just going to
- 2:09:03clear the screen over here and we are
- 2:09:05just going to verify whether our changes
- 2:09:07has been reflected there or not so I'm
- 2:09:09just going to rerun the cat command to
- 2:09:11view the changes and if we scroll up and
- 2:09:14here you can see so we are able to
- 2:09:16update our server configuration just by
- 2:09:18running the Playbook so that's the power
- 2:09:21of your Ginger to template which you can
- 2:09:23extend and customize your anible
- 2:09:26playbook so that was all about the
- 2:09:28ginger to template in anible Playbook
- 2:09:30and so far we have covered sixth chapter
- 2:09:33and in the next chapter we will be
- 2:09:35talking more about the deployment
- 2:09:37strategy and where we will talk about
- 2:09:39like how you can use the anible Playbook
- 2:09:41on a single server and when you can use
- 2:09:43the same anible Playbook to run on a
- 2:09:45multiple server so that's going to be
- 2:09:48the next Topic in this series and if you
- 2:09:50new to this channel then please please
- 2:09:51considering subscribing to this channel
- 2:09:53where you will see the similar content
- 2:09:55onto the devops especially like a
- 2:09:57terraform anible AWS gcp kubernetes and
- 2:10:01Docker so please considering subscribing
- 2:10:03to this Channel and if you have any
- 2:10:05question related to the today's session
- 2:10:06then please put down into the comment
- 2:10:08section and I'll try to get back to you
- 2:10:10so see you into the next session of the
- 2:10:11sensible series till then take care and
- 2:10:15bye-bye there are various deployment
- 2:10:17strategies when you are using anible to
- 2:10:19automate your deployment processes but
- 2:10:21on a very high level you can put the
- 2:10:23deployment strategies into two category
- 2:10:25one is the single server deployment and
- 2:10:27second is the multi-server deployment
- 2:10:29for ansible in this lab session we are
- 2:10:31going to discuss about the deployment
- 2:10:33strategies and specifically we will be
- 2:10:35talking about how to manage the
- 2:10:36deployment on all the servers when
- 2:10:38you're working with the anible second we
- 2:10:40are just going to take a look on how to
- 2:10:42deploy or manage the deployment on a
- 2:10:44subset or a selected server out of all
- 2:10:47the servers and finally we are just
- 2:10:49going to take a look onto the blue and
- 2:10:51green green strategy also so how you can
- 2:10:53implement the blue and green deployment
- 2:10:55strategy for your anible automation
- 2:10:57before we start talking about the
- 2:10:59complex deployment strategy let's take a
- 2:11:01very simple example and understand how
- 2:11:03you will manage the deployment on a
- 2:11:05single server let's take a look onto the
- 2:11:07project structure where I have created a
- 2:11:09sample project in which I'm targeting
- 2:11:11only single server deployment with my
- 2:11:13anible playbook so this is the host file
- 2:11:16which is present inside my uh project
- 2:11:18and this is the definition or the
- 2:11:20configuration which is present inside my
- 2:11:22host file and you can see over here
- 2:11:24that's only one IP address which I have
- 2:11:26mentioned so this is the remote server
- 2:11:28where I'll be doing the deployment and
- 2:11:31just to keep the thing simple what I'll
- 2:11:32be doing I'll be installing the python
- 2:11:34on my remote server using this anible
- 2:11:37Playbook and since our host file only
- 2:11:40contains single server so this whole
- 2:11:42Playbook will be responsible for
- 2:11:43managing the deployment on a single
- 2:11:46server okay that's being said let's take
- 2:11:48a look onto the anible Playbook command
- 2:11:50so here you you can see this is the
- 2:11:52anible Playbook command which I have
- 2:11:53written over here so this is the anible
- 2:11:55Playbook keyword which you need to
- 2:11:57mention then you need to specify the
- 2:11:59inventory and the host file which you
- 2:12:01can see over here so this is the host
- 2:12:03file path where I have defined my host
- 2:12:06host IP and after that the actual
- 2:12:09Playbook name so the name of the
- 2:12:10Playbook is anible deployment strategy.
- 2:12:12yml so that's the command which you need
- 2:12:15to execute to run this particular
- 2:12:17Playbook one thing to keep in mind over
- 2:12:19here since it's a single server
- 2:12:21deployment and I have not used any host
- 2:12:23or I have not limit this particular
- 2:12:25Playbook to run on a single host since I
- 2:12:28have not specified any host inside my
- 2:12:30anible command I'm talking about this
- 2:12:32particular anible command so what it
- 2:12:34will do it will just go and execute this
- 2:12:36an Playbook on this default host which I
- 2:12:39have mentioned inside my host file so
- 2:12:41you just simply need to run this
- 2:12:43Playbook and it will execute the whole
- 2:12:45uh anible deployment for that particular
- 2:12:48host and don't worry we are just going
- 2:12:50to perform a in the second part of this
- 2:12:52lab session where I'm just going to show
- 2:12:54you like how to do the single server
- 2:12:55deployment and how to do the multi-
- 2:12:57server deployment using an all right so
- 2:13:00now we have seen the single server
- 2:13:01deployment and how to manage the single
- 2:13:03server host inside our host file let's
- 2:13:06discuss more onto the multi- server
- 2:13:07deployment using anel so here onto the
- 2:13:10screen I have taken one example and this
- 2:13:12is my anel project which you can see and
- 2:13:15this is the host file where I have
- 2:13:16defined the multi- server host
- 2:13:18configuration so this is the host file
- 2:13:21which I have uh taken a screenshot over
- 2:13:23here and I have categorized my host into
- 2:13:26two category one is the blue and second
- 2:13:28one is the green so in the blue uh like
- 2:13:30a category I have two uh IP addresses so
- 2:13:33these are the two remote machines which
- 2:13:35I am using and here in the green also I
- 2:13:38have specified two remote IPS so here
- 2:13:40this is the third and this is the fourth
- 2:13:42server so here I'm managing the fourth
- 2:13:44server and I'm trying to deploy or
- 2:13:47automate this deployment process using
- 2:13:49the anible for our four remote host
- 2:13:51machine now you might be wondering like
- 2:13:54what is this blue and green category so
- 2:13:56whenever you're having more than one
- 2:13:58server then it is always difficult to
- 2:14:00remember the IP addresses of each server
- 2:14:03so what we do in anible is like we
- 2:14:05create a category and here we have
- 2:14:06created two category one is the blue and
- 2:14:08second one is the green let's talk about
- 2:14:10the green category so in the green
- 2:14:12category in our example we are having
- 2:14:14two servers and those two servers are
- 2:14:17actively running in the production
- 2:14:18environment and actively serving the
- 2:14:20reest from active customer so our
- 2:14:23applications are live and those are
- 2:14:25accessible uh by our clients but the
- 2:14:28blue category is also a production
- 2:14:30environment but that is not actively
- 2:14:32serving the request from the clients so
- 2:14:35just to ease out the thing I will put
- 2:14:37active over here and this one is passive
- 2:14:41over here so what happens over here is
- 2:14:44like whenever you're doing the release
- 2:14:46then what you're going to do you're just
- 2:14:47going to perform the production release
- 2:14:49on a blue category of a server because
- 2:14:52your blue category of a production
- 2:14:54server are not serving the actual
- 2:14:56client's request but the green category
- 2:14:58of a servers are actually serving the
- 2:15:00client request so you are not going to
- 2:15:02touch the green side of it you just stay
- 2:15:05away during the production release
- 2:15:06you're just going to do the deployment
- 2:15:08and release on a blue category of
- 2:15:10servers and once you done with those
- 2:15:12deployment on your blue category of a
- 2:15:14servers then what you're going to do
- 2:15:16you're just going to decommission or
- 2:15:18you're just going to put off the uh
- 2:15:20traffic onto the green side of the
- 2:15:22server so you're just going to cut the
- 2:15:24all the traffic which are coming towards
- 2:15:26the green and then you're just going to
- 2:15:27redirect all this traffic towards the
- 2:15:29blue category the benefit of this
- 2:15:32deployment strategy with anel is that
- 2:15:34you don't have to put the downtime on
- 2:15:36your production server your applications
- 2:15:38are always available and you just need
- 2:15:40to switch the server from green to the
- 2:15:43blue server that being said then how
- 2:15:45you're going to implement this thing
- 2:15:46using the anible Playbook command so
- 2:15:49here there are a couple of flags which
- 2:15:50you need need to use so whenever you're
- 2:15:52just doing the production deployment on
- 2:15:53a blue side then you just need to use
- 2:15:55this particular limit flag so just type
- 2:15:59your anible playbook command onto your
- 2:16:01terminal and just Supply this flag at
- 2:16:03the end of this and at the end of your
- 2:16:05anible playbook command and this whole
- 2:16:08deployment will run onto the blue
- 2:16:10category of servers and here is an
- 2:16:12example command which I have uh
- 2:16:14mentioned over here there is a
- 2:16:15screenshot so here you can see this is
- 2:16:16the limit flag which I'm using along
- 2:16:18with my anible playbook command so this
- 2:16:21is the way you can just manage the uh
- 2:16:23deployment uh using this limit flag and
- 2:16:26you can Target the servers which are
- 2:16:28present under the blue category let's
- 2:16:30start with the demo and here onto the
- 2:16:32screen you can see this is the part 12
- 2:16:34and this is the project which I have
- 2:16:35created for this deployment strategy and
- 2:16:37I'll put the link of this particular
- 2:16:39project into the GitHub section so feel
- 2:16:41free to clone that particular project
- 2:16:43all right so talking about this project
- 2:16:45so first of all let's take a look onto
- 2:16:47the host file and first we will Target
- 2:16:49onto the single server deployment so
- 2:16:51this is the host file and inside the
- 2:16:53host file I have created a default and
- 2:16:55default category and inside the default
- 2:16:57category I have mentioned the IP address
- 2:16:59of my remote machine so I'm just going
- 2:17:02to run this Playbook and this Playbook
- 2:17:04is going to run on this default machine
- 2:17:06this this default remote server so what
- 2:17:08I'm going to do I'm just going to open
- 2:17:10the readme file over here I'm just going
- 2:17:12to copy this
- 2:17:14command go to terminal I'm just going to
- 2:17:17clear the screen I'll just go to the
- 2:17:19directory where my project
- 2:17:22is clear the screen I'm just going to
- 2:17:24shorten this path so that it is visible
- 2:17:28to you
- 2:17:30also okay I'm just going to clear it and
- 2:17:32I'm just going to paste the command over
- 2:17:33here and here you can see in this
- 2:17:35Playbook command I'm not specifying any
- 2:17:37limit so I just want this Playbook to
- 2:17:39run on all the host which are present
- 2:17:42inside my host file simply type enter
- 2:17:45type
- 2:17:47yes now my NC Playbook has just finished
- 2:17:50and it has inst install python onto my
- 2:17:52remote server with this particular IP
- 2:17:54address all right so now we have seen
- 2:17:56the single server deployment strategy
- 2:17:58using the Nal let's update the host file
- 2:18:00and put the blue and green category
- 2:18:02along with the servers so I'm just going
- 2:18:04to go to my project I'm just going to
- 2:18:06open my host file and I'm just going to
- 2:18:09erase everything from here and I'm just
- 2:18:11going to add the blue and green category
- 2:18:13along with the remote server server IP
- 2:18:16address let's open the readme file over
- 2:18:18here once again and here I have
- 2:18:20mentioned the anible Playbook command
- 2:18:22with the limit flag so what you need to
- 2:18:24do is you need to remove the line braks
- 2:18:26over here otherwise you might not be
- 2:18:28able to run the sensible Playbook okay
- 2:18:30that's been done so I'm just going to
- 2:18:32copy this command from here I'm just
- 2:18:34going to head over to terminal I'm just
- 2:18:36going to clear the screen and I'm just
- 2:18:38going to place the command over here so
- 2:18:40here you can see I'm just running the
- 2:18:41sensible Playbook with the limit blue so
- 2:18:43I'm just going to update the blue
- 2:18:45category of servers so simply hit enter
- 2:18:49type yes
- 2:18:51all right so now my ncble playbook has
- 2:18:53just finished and as you can see there
- 2:18:55are two IP address which has been
- 2:18:57updated so one of them is like this one
- 2:18:5952 59 205 and 47 so this particular one
- 2:19:03which I have highlighted which I have
- 2:19:04already uh where I have already
- 2:19:07installed the python when I did the
- 2:19:08single server deployment but this is the
- 2:19:11second IP uh which is from the blue
- 2:19:13category and that has been updated or
- 2:19:15where I have installed python using the
- 2:19:17anel and we can verify both the IP
- 2:19:19addresses so let's let's open the host
- 2:19:21file once again and I'm just going to
- 2:19:23open the terminal over here also so that
- 2:19:25you can see so as you can see over here
- 2:19:28so 5259 205 and 47 so that's the IP
- 2:19:32address under blue category and the
- 2:19:33second IP address was 18 19423 and 12 so
- 2:19:38that's the second IP address so these
- 2:19:40are the two uh category of a those two
- 2:19:43servers under the blue category I have
- 2:19:45updated uh using the N so that's how
- 2:19:47you're just going to limit uh the
- 2:19:49servers which you want to put under the
- 2:19:52deployment of anible and using the same
- 2:19:54limit flag you do the production
- 2:19:56deployment for the green category of a
- 2:19:58servers also you just need to change the
- 2:20:00name of the limit flag so this is how
- 2:20:03you're just going to manage the
- 2:20:04deployment strategy or you're just going
- 2:20:06to manage the deployment on a
- 2:20:08multi-server environment like generally
- 2:20:10we have in our production I hope this
- 2:20:12short session on this deployment
- 2:20:13strategies with anel will help you to
- 2:20:15manage and streamline your production
- 2:20:17strategies uh of deployment with anel
- 2:20:20and if you're interested into the
- 2:20:21similar devops concept on anible
- 2:20:24terraform AWS kubernetes Helm chart
- 2:20:26Docker then please considering
- 2:20:28subscribing to this channel where I keep
- 2:20:29on sharing the similar content on a
- 2:20:31weekly basis so see you into the next
- 2:20:33session of anible or devops till then
- 2:20:35take care and
- 2:20:37bye-by error handling is really a
- 2:20:40powerful feature which helps you to
- 2:20:42address the unexpected errors which may
- 2:20:44occur when you are running your anible
- 2:20:45playbook let's talk about the couple of
- 2:20:47scenarios which might help you to
- 2:20:49understand why you should need need
- 2:20:50error handling in your anible playbook
- 2:20:53let's assume that you have a two server
- 2:20:55and you need to copy a particular file
- 2:20:57onto both the server but what happens is
- 2:21:00that when you're running an anible
- 2:21:01Playbook you notice that one of the
- 2:21:03server is offline and you cannot reach
- 2:21:04to that particular server and once you
- 2:21:06cannot reach to that particular server
- 2:21:08that means you cannot copy a file to
- 2:21:10that particular server but although the
- 2:21:12second server is online and you are
- 2:21:14still able to perform a copy onto that
- 2:21:16server so if you don't use any kind of
- 2:21:19error handling over here here then your
- 2:21:21anible playbook will fail and eventually
- 2:21:23you will not be able to copy the same
- 2:21:25file onto the another server which is up
- 2:21:27and running so in such a scenario what
- 2:21:29you can do you can just use the ignore
- 2:21:31error flag inside your anible playbook
- 2:21:34so what it will do it will just let
- 2:21:36ignore that particular error when you're
- 2:21:38trying to execute the anible Playbook so
- 2:21:40what will happen is that you will just
- 2:21:43skip that particular error and but you
- 2:21:44will move to the next server and you
- 2:21:46will just copy that file onto the second
- 2:21:48server so with the help of the sign
- 2:21:50error you can just ignore such kind of
- 2:21:52Errors happening into your anible
- 2:21:54playbook let's take another use case
- 2:21:56where you want to forcefully fail the
- 2:21:58execution of your anible playbook and
- 2:22:00for this use case let's assume that you
- 2:22:02are trying to copy a config file which
- 2:22:04is really necessary for your production
- 2:22:06deployment but what you notice is that
- 2:22:08that the destination path is incorrect
- 2:22:10and you are not able to copy that
- 2:22:12particular config file onto your
- 2:22:13destination server and since this config
- 2:22:16file is really important for your
- 2:22:17production deployment so you want to
- 2:22:19forcefully fail that anible Playbook so
- 2:22:21in such kind of a scenario you need to
- 2:22:23use a flag any error fatal so this
- 2:22:26particular flag will help you to
- 2:22:28forcefully stop the anible Playbook
- 2:22:30execution and you need to fix that error
- 2:22:32before moving to the next deployment now
- 2:22:35I have explained to you the couple of
- 2:22:36flags which you can use for your anible
- 2:22:38playbook now I would like to switch over
- 2:22:40to my desktop and show you like how we
- 2:22:42can use those flag inside our anible
- 2:22:45playbook for error handling all right so
- 2:22:47this is my anible playbook and the first
- 2:22:49task where we are just going to see is
- 2:22:51the ignore errors flag so here let me
- 2:22:53explain this particular task and how we
- 2:22:55are going to simulate this particular
- 2:22:57error and then we are just going to
- 2:22:58ignore that particular error so here at
- 2:23:00line number four if you pay attention
- 2:23:02then I'm just trying to copy index.html
- 2:23:05to my remote server at this particular
- 2:23:08path and the path is home u 2 so I'm
- 2:23:10just going to first of all show you my
- 2:23:12remote server so this is my remote
- 2:23:15server and if I do the PWD so this is
- 2:23:17the path where I would like to copy that
- 2:23:19index. HTML
- 2:23:21but to simulate this ignore error what I
- 2:23:24did is I just didn't provided the
- 2:23:26index.html so this index.html is
- 2:23:29completely missing so when this task run
- 2:23:31then it will not be able to find the
- 2:23:32index. HTML and if it is not able to
- 2:23:35find the index. HTML then it will result
- 2:23:38into error and at line number six I have
- 2:23:40put the flag that ignore errors that's
- 2:23:43true so which means if there is any
- 2:23:45error in involved in this particular
- 2:23:47task then this particular flag flag is
- 2:23:50going to to ignore that particular error
- 2:23:52let's run this Playbook and if you are
- 2:23:54looking for this particular project then
- 2:23:55I'll provide the GitHub repository link
- 2:23:57of this particular project into the
- 2:23:59description section so feel free to use
- 2:24:01that particular Rao so here I have
- 2:24:03created a readme file uh which you can
- 2:24:05copy The anible Playbook command from
- 2:24:07here and also I would like to show you
- 2:24:10uh that this index.html so ideally I'm
- 2:24:14expecting this index.html to be present
- 2:24:16along with my main. yml but this
- 2:24:18particular file I have not provided it
- 2:24:20all over here so that's just a a small
- 2:24:22thing I would like to mention before
- 2:24:23running the anible playable so I'm just
- 2:24:26going to head over to my terminal I'm
- 2:24:28just going to open another one I'm just
- 2:24:30going to clear the screen and I'm just
- 2:24:31going to paste the command over here and
- 2:24:33simply hit
- 2:24:37enter and here you can see uh index HTML
- 2:24:41copy with ignore error so that was our
- 2:24:43task name so you which you can see over
- 2:24:45here that was our task name and if you
- 2:24:47open the terminal then here you can see
- 2:24:50could not find or access index.html so
- 2:24:53which tells you that this index.html is
- 2:24:55completely missing and anible Playbook
- 2:24:57couldn't find that
- 2:24:59index.html but since we have used that
- 2:25:01particular flag so it is ignoring this
- 2:25:03particular error which you can see over
- 2:25:05here and at the same time if you look at
- 2:25:08uh the final result of the sensible
- 2:25:10Playbook then you will see that it has
- 2:25:12completed but it has ignored that
- 2:25:14particular task so this is how you're
- 2:25:16just going to use the ignore error flag
- 2:25:18inside your anible playbook where you
- 2:25:20want to intentionally ignore any error
- 2:25:23which is happening inside your anible
- 2:25:25task moving to the next anible task
- 2:25:27where I would like to forcefully fail my
- 2:25:29anible playbook and for that I'm just
- 2:25:31going to use the any errors fatal flag
- 2:25:34inside my anible task so here I'm just
- 2:25:36going to take the same example so here
- 2:25:38again I'm just trying to copy the
- 2:25:39index.html and this index.html is
- 2:25:42missing and I'm just trying to copy at
- 2:25:44the same path but here I just put some
- 2:25:47conditions over here so the first
- 2:25:49condition which I have put over here is
- 2:25:50the any errors fatle which is true if
- 2:25:53this flag is true and if there are any
- 2:25:55error associated with this particular
- 2:25:57task then my whole anible Playbook is
- 2:25:59going to fail but I need to provide the
- 2:26:02condition when this condition is me then
- 2:26:06make this particular task fail for this
- 2:26:08particular anible Playbook so we need to
- 2:26:10use or we need to specify a condition
- 2:26:12and that condition you can specify using
- 2:26:15the failed van so you need to use two
- 2:26:17attributes over here so first attribute
- 2:26:19we are just going to use is any errors
- 2:26:21fatle so that your whole anible Playbook
- 2:26:23will fail but you need to specify the
- 2:26:25condition when this particular condition
- 2:26:27is met then make this whole anible
- 2:26:29Playbook fail and for that we are just
- 2:26:31going to use the fail when flag inside
- 2:26:33your anible task let's take a closer
- 2:26:36look onto the failed when condition and
- 2:26:38how I specified it so here at line
- 2:26:40number 17 you will see a message like
- 2:26:43could not find or access so this is a
- 2:26:45particular error message I'm looking
- 2:26:47into but where I'm looking this
- 2:26:49particular error message so if you take
- 2:26:51a look onto the previous task then here
- 2:26:54I'm just trying to capture the result of
- 2:26:57this particular operation which is a
- 2:26:59copy operation so here it is trying to
- 2:27:01perform a copy operation and whatever
- 2:27:03happens in that operation I'm just
- 2:27:05trying to register that output into this
- 2:27:07particular variable that is copy result
- 2:27:10so what I'm expecting is that in that
- 2:27:13copy result uh variable I'm expecting a
- 2:27:16message and that message should contain
- 2:27:18could not find or access although that
- 2:27:21message is going to be a really long one
- 2:27:23but I just want to find this particular
- 2:27:24words inside that message so if you're
- 2:27:27trying to copy a particular file and if
- 2:27:29that file doesn't exist then it will
- 2:27:31result some error and that result error
- 2:27:33message will contain could not find or
- 2:27:35access index.html and I'm just trying to
- 2:27:38find that particular keywords inside
- 2:27:40that particular message so once that
- 2:27:43condition or when once that keyword I'm
- 2:27:45able to find it then I'm just going to
- 2:27:47evaluate that particular condition so
- 2:27:49here have specified this particular
- 2:27:51string and it should be present into the
- 2:27:53copy result. message and if it is
- 2:27:55present then I'm just going to make it
- 2:27:57fail and this condition will get true
- 2:27:59and similarly there will be one more
- 2:28:01flag which will be coming along with
- 2:28:03this copy result because this is a like
- 2:28:05a registered variable and it will have a
- 2:28:06lot of attribute which I'm just going to
- 2:28:08show you next so inside that I also like
- 2:28:11to check whether that particular task
- 2:28:13failed status is true so when these both
- 2:28:17conditions are met then I'm just going
- 2:28:19to evaluate these condition and both the
- 2:28:21conditions are true and then I'm just
- 2:28:23going to make this uh particular any
- 2:28:25errors fatal flag true and this whole
- 2:28:28anible Playbook will fail but before we
- 2:28:30run this anible Playbook I would like to
- 2:28:31enable one more task where I would like
- 2:28:33to show you that register variable and
- 2:28:35what it holds inside it so here I have
- 2:28:38just put a debug on that particular
- 2:28:40register variable so I'm just going to
- 2:28:42enable this particular task also so that
- 2:28:44you can see what's happening inside or
- 2:28:45what are the values present inside this
- 2:28:47particular copy result variable so I
- 2:28:49have just enable this particular debug
- 2:28:52so when I'm just going to run the
- 2:28:53sensible Playbook so it is going to spit
- 2:28:55out uh what are the content inside this
- 2:28:57particular message and then we are just
- 2:28:59going to see like what are the condition
- 2:29:01which it is evaluating inside this third
- 2:29:03task okay so I'm just going to open the
- 2:29:05terminal over here I'm just going to
- 2:29:07clear the screen and I'm just going to
- 2:29:09run the ncble
- 2:29:11Playbook and here you can see uh we'll
- 2:29:14just start from the first so this is our
- 2:29:16first use case where we have ignored
- 2:29:18that particular error now second and
- 2:29:20string variable from men Playbook so
- 2:29:22this is where I'm just trying to print
- 2:29:24the values or whatever message which is
- 2:29:26present inside that copy uncore result
- 2:29:28variable which I have registered so
- 2:29:30which you can see over here I'm just
- 2:29:32trying to print the values onto the
- 2:29:34console so that I can see what are the
- 2:29:35values present inside this particular
- 2:29:37register variable okay so the key thing
- 2:29:40which we need to look over here is we
- 2:29:42need to find this particular text inside
- 2:29:44that message and also the uh flag which
- 2:29:47is like copy result. should be true
- 2:29:50so I'm just going to open the terminal
- 2:29:52and uh first of all this is the variable
- 2:29:55that is copy underscore result that's
- 2:29:56okay and then I'm just going to find the
- 2:29:59keyword so here you can see could not
- 2:30:00find or access so this particular
- 2:30:03keyword I'm just trying to find as an
- 2:30:04string inside that particular variable
- 2:30:07so yeah that is present and also I'm
- 2:30:10just going to try to find this copy
- 2:30:12result and here is the file and that is
- 2:30:14true so these are the two condition I
- 2:30:17was force forcing uh in that particular
- 2:30:19task to be evaluated and these both
- 2:30:22conditions are met and once these two
- 2:30:24conditions are met then I'm just making
- 2:30:26this whole anible Playbook fail with the
- 2:30:28any errors fatal fly so if you move down
- 2:30:31further then here you can see here I'm
- 2:30:33just trying to copy using failed when
- 2:30:35and any error fatal flag and here you
- 2:30:38can see this whole Playbook has just
- 2:30:40failed and here you can see the final
- 2:30:42status of our ncble Playbook that is
- 2:30:44failed equals 1 and ignore equals 1 so
- 2:30:46ignore one was our first use case and
- 2:30:49this is our second task where we have
- 2:30:51forcefully failed the whole anible
- 2:30:53Playbook all right so now we have seen
- 2:30:54the any errors fatal flag so what I'm
- 2:30:56just going to do I'm just going to set
- 2:30:58it to
- 2:30:59false before moving to the next uh
- 2:31:02anible task where I'm just going to show
- 2:31:04you the another flag which is like a
- 2:31:06changed B but to go to the next task
- 2:31:09what I need to do is I need to first of
- 2:31:10all enable this
- 2:31:12one and why I set it to false because if
- 2:31:15I don't set it to false then I will not
- 2:31:17be able to run this particular task in
- 2:31:20the next in my anible playbook so that's
- 2:31:22why I need to forcefully set it to false
- 2:31:24all right now I have set it to false the
- 2:31:26next thing which I'm just trying to do
- 2:31:27over here in this task is to use the
- 2:31:29changed when so changed when is just an
- 2:31:32another error handling kind of things in
- 2:31:35anible pbook uh which tells you like if
- 2:31:37something has changed onto the remote
- 2:31:40server so that's where we are just going
- 2:31:41to use the changed when uh flag inside
- 2:31:44your anible playbook so what I'm just
- 2:31:46going to do over here is that I'm just
- 2:31:48going to touch a file so I'm just going
- 2:31:50to create a simple file with the name my
- 2:31:53my file.txt onto the my remote server
- 2:31:56onto this particular location that is
- 2:31:58homeor ub2 and I'm just going to show
- 2:32:01you that whether that file is present or
- 2:32:03not I'm just going to clear it the path
- 2:32:05is home/ to LS and here you can see the
- 2:32:09uh that particular directory is empty
- 2:32:11and there is no file which is created
- 2:32:12over there so this ncble Playbook what
- 2:32:15it will do it will just create a file
- 2:32:17that is my file.txt and it will register
- 2:32:20that output of this particular command
- 2:32:22into this particular variable and once
- 2:32:25that uh output is registered into this
- 2:32:27variable then I'm just going to check uh
- 2:32:30that that RC uh request for change is
- 2:32:33zero or not if it's zero that means that
- 2:32:36particular file has been created and if
- 2:32:38it's other than zero then that means
- 2:32:40that file has not been created onto the
- 2:32:42remote server now I would like to
- 2:32:44correct one thing over here I I
- 2:32:45mentioned the name of this particular uh
- 2:32:48RC flag is request for change but it's
- 2:32:50actually a result code that's the actual
- 2:32:52full form of that particular RC having
- 2:32:55said that let's switch over to terminal
- 2:32:56and run the sensible Playbook and we'll
- 2:32:58see if we are able to create this
- 2:32:59particular file or not onto my remote
- 2:33:01server so I'm just going to open the
- 2:33:03terminal and I'm just going to run the
- 2:33:05command or to execute my anible
- 2:33:08playbook and we'll start from the first
- 2:33:10so here this was our first task for
- 2:33:12ignoring the error secondly uh we were
- 2:33:16just trying to uh set the value of any
- 2:33:19errors ftles flag to false so now we are
- 2:33:21not we are not forcefully failing our
- 2:33:23flag so this task has also been passed
- 2:33:26now the third task is which is this one
- 2:33:28and which we are just going to evaluate
- 2:33:30so here this is the name of the task
- 2:33:31create a file if it does not exist so
- 2:33:34I'm just going to head over to terminal
- 2:33:36and this is the task and the changed
- 2:33:38which means uh something has changed
- 2:33:40onto this particular task and here you
- 2:33:43can see the result that is changed
- 2:33:44equals 1 which means that we are able to
- 2:33:47create a file onto our remote server and
- 2:33:49and the output is registered into this
- 2:33:51variable and the value of that
- 2:33:53particular uh code is zero so that means
- 2:33:56our file has been created onto the
- 2:33:58remote server and we can go to the
- 2:34:00terminal and this is my terminal and I'm
- 2:34:03just going to run the ls command and
- 2:34:05here you can see my file.txt
- 2:34:07so this is how you're just going to use
- 2:34:10this particular changed van flag and you
- 2:34:12can use this particular code associated
- 2:34:15with this RC and you can specify it as a
- 2:34:17zero so which means that something has
- 2:34:19changed onto the remote server and that
- 2:34:21change is creating a just a file so this
- 2:34:24was just an example for using how you
- 2:34:27can use the changed van flag inside your
- 2:34:29anible task so this was a small lab
- 2:34:31session on error handling in anible in
- 2:34:34the next Lab session we are just going
- 2:34:35to talk about the anible Vault and how
- 2:34:37you can store the secure information
- 2:34:39inside your anible Vault and that's
- 2:34:41going to be a little bit a longer
- 2:34:42session because there we will be
- 2:34:44creating an anible Vault and then we
- 2:34:45will be storing some Secrets inside that
- 2:34:47enens Vault and using those Secret
- 2:34:49inside our anible Playbook so that is
- 2:34:52going to be the next session and if
- 2:34:53you're interested into the similar
- 2:34:54content on devops then please
- 2:34:56considering subscribing to this channel
- 2:34:57where I keep on sharing the similar
- 2:34:59topics on a weekly basis so see you into
- 2:35:01the next session of ncble or devops till
- 2:35:03then take care and
- 2:35:05bye-bye anible vault is a really
- 2:35:08important concept when you want to
- 2:35:09encrypt the data which you don't want to
- 2:35:11show in a plain text format while
- 2:35:13working with your anible playbook since
- 2:35:15we are talking about the anible VA then
- 2:35:17we should know the basic command on how
- 2:35:19to operate on anible vault so the First
- 2:35:22Command which we will take a look is
- 2:35:24anible Vault create which will help you
- 2:35:26to create an anible Vault from the
- 2:35:28scratch second once you create an anible
- 2:35:30Vault then how you're just going to edit
- 2:35:32the content present inside the anible
- 2:35:34Vault so the second command which we are
- 2:35:36going to take a look is the anible Vault
- 2:35:38edit and the third one is the anible
- 2:35:41Vault view which can help you to view
- 2:35:43the content in a readon mode present
- 2:35:45inside your anible VA apart from anible
- 2:35:48Vault basic command the second thing we
- 2:35:50are going to take a look like how to use
- 2:35:52your anible Vault when you're executing
- 2:35:54your anible playbook and there are three
- 2:35:57ways you can use your anible Vault the
- 2:35:59first way to use your anible Vault while
- 2:36:01executing or while running your anible
- 2:36:03playbook is to supply the parameter ask
- 2:36:05VA pass so when you supply this
- 2:36:08parameter along with your anible
- 2:36:10playbook command then you need to key in
- 2:36:12or you need to enter your uh Vault
- 2:36:14password and once you supply your Vault
- 2:36:16password then you will be able to fetch
- 2:36:18your secrets from your ncble vault which
- 2:36:20are instored inside your encrypted yml
- 2:36:23file the second way of using the ncble
- 2:36:25vault is to store the password inside a
- 2:36:28Vault password file so that you don't
- 2:36:30need to key in or you don't need to
- 2:36:32enter the password from the command line
- 2:36:34you can simply store your password for
- 2:36:36your Vault inside a plain text file and
- 2:36:39then you can supply that file uh while
- 2:36:41you're executing your anible playbook
- 2:36:44and the third way of using the ncble
- 2:36:45vault is to export the path of your
- 2:36:47ncble Vault password file into the
- 2:36:50environment variable and the benefit you
- 2:36:52will get from that is you don't need to
- 2:36:54enter the password of your anible Vault
- 2:36:57and also you don't need to supply the
- 2:36:59path of your ncble Vault password file
- 2:37:01while you're executing the ncble
- 2:37:03Playbook you can just simply run your
- 2:37:04ncble playbook let's switch to my code
- 2:37:07editor and the first thing we'll start
- 2:37:09is by creating our anible vault so this
- 2:37:11is my code editor and this is the part
- 2:37:1314 and this whole project is available
- 2:37:16onto my GitHub repository so I'll post
- 2:37:18the link of my GitHub repository into
- 2:37:20the description section so feel free to
- 2:37:22clone this particular code repository
- 2:37:24for your own use let's start with the
- 2:37:26walk through of My ncble Vault project
- 2:37:28so here this is the part 14 anible VA
- 2:37:31which I have already created and inside
- 2:37:33that project you will find a readme file
- 2:37:35which I have already opened over here so
- 2:37:37here I have written down all the
- 2:37:38commands which I'm just going to use
- 2:37:40inside this particular demo so the first
- 2:37:43thing which we are going to do is we are
- 2:37:44just going to create an anible Vault and
- 2:37:46for that the command is anible VA create
- 2:37:49and then after that you need to supply
- 2:37:51the path so here I will be creating My
- 2:37:53anible Vault yml inside the groups War
- 2:37:56directory and the name of my vault yml
- 2:37:58is my vault. yml I'll copy the command
- 2:38:01from here to create my anible Vault so
- 2:38:04I'll copy the command I'll go to
- 2:38:06terminal and I'll just past the command
- 2:38:08over here hit enter and as soon as you
- 2:38:11hit the enter then it will ask you to
- 2:38:13set a password for your anible VA so
- 2:38:15here I'm just going to set a
- 2:38:17password and it is again going to
- 2:38:19confirm the same password which you have
- 2:38:21entered so I'm just going to re enter my
- 2:38:24password and here you can see our anible
- 2:38:26vault has been created and now it has
- 2:38:29opened my anible vault yml which is my
- 2:38:32vault. yml so here this is open uh into
- 2:38:36the edit mode and you can use the vi
- 2:38:39command to enter your like a secret
- 2:38:41inside your anible Vault so here I'm
- 2:38:44just going to press I from the keyword
- 2:38:46so that I can go into the insert mode
- 2:38:48and the first thing which I'm just going
- 2:38:49to create is like my uh Vault or maybe I
- 2:38:53can type in like my secret and then I
- 2:38:56can enter uh this
- 2:38:59is the first
- 2:39:02secret from anible Vault so this is the
- 2:39:06uh secret text which I'm keying in
- 2:39:08Inside My anible Vault and once you have
- 2:39:11entered your secret then what you can do
- 2:39:12you can press the escape from your
- 2:39:14keyboard and then save and quit which is
- 2:39:16w and Q and then hit enter
- 2:39:19so by this way you are just going to
- 2:39:21create your first anible Vault inside
- 2:39:23your anible project and if you go back
- 2:39:26to your project structure over here then
- 2:39:28in the group ports you will find a file
- 2:39:31that is myor wall. yml which has been
- 2:39:34created and if you double click on it
- 2:39:36then you can see this whole content
- 2:39:38inside that particular file is encrypted
- 2:39:41and you cannot view the content which we
- 2:39:43have written which we have written a
- 2:39:45simple message Inside My ncble Vault
- 2:39:47since we have created our first n VA
- 2:39:49then second command which I would like
- 2:39:51to run is to view the content of my
- 2:39:53anible VA so again go to this readme
- 2:39:56file and here I have written the view
- 2:39:58command to view the content of your
- 2:40:00anible Vault and remember this is going
- 2:40:02to be a readon mode you cannot edit
- 2:40:04anything inside your anible Vault and
- 2:40:07the command for that is anible Vault uh
- 2:40:10after that you need to supply the
- 2:40:12keyword view to view the content and
- 2:40:14then after that you need to supply the
- 2:40:15path of that particular file which you
- 2:40:17have just created so I'm just going to
- 2:40:19copy this command from here I'm just
- 2:40:21going to head over to terminal and I'm
- 2:40:22just going to paste the command and hit
- 2:40:24enter and as soon as you hit the enter
- 2:40:27to view the content of your anible Vault
- 2:40:29then it is going to ask for the password
- 2:40:31which you have set when you were when
- 2:40:33you were creating that anible Vault so
- 2:40:35I'm just going to supply the password
- 2:40:37and hit enter and here you can see the
- 2:40:39message uh or the secret message which
- 2:40:41we have written inside our anible W so
- 2:40:44the uh message which we have uh for that
- 2:40:46created is first of all we have created
- 2:40:48a variable that is myor secret and this
- 2:40:51is the secret message which we have key
- 2:40:53in inside my anible B well this is just
- 2:40:56a demo but this anible Vault can be used
- 2:40:59for securing your password which can be
- 2:41:01your database passwords also so here you
- 2:41:04can key in your strong password which is
- 2:41:06really sensitive and you can place those
- 2:41:08uh sensitive information inside your
- 2:41:10anible Vault all right so now we have
- 2:41:12created an anible Vault and we have seen
- 2:41:15like how to view the content of My
- 2:41:16anible Vault the next thing which I'm
- 2:41:18just going to do is I'm just going to
- 2:41:20use that anible Vault or the password
- 2:41:23which we have or the secret text which
- 2:41:25we have created or inserted inside my
- 2:41:27anible VA into my anible playbook so
- 2:41:30here if you take a look carefully so
- 2:41:32this is the uh variable uh which is
- 2:41:34storing my sensitive information so I'm
- 2:41:37just going to use this variable to print
- 2:41:39the value or to debug that particular
- 2:41:41value inside my ncble pleb well this is
- 2:41:44just a demo where that's why I'm just
- 2:41:46I'm just using the debug but in case if
- 2:41:48you want to use this for particular
- 2:41:51let's say for example uh creating a
- 2:41:53database connection and you want to
- 2:41:54print uh or you want to use the database
- 2:41:57password then you can use a similar
- 2:41:59approach and just Supply your variable
- 2:42:02where which is storing your database
- 2:42:04password so this is just in another
- 2:42:06example in the real time scenario how
- 2:42:07you're just going to use this uh secret
- 2:42:09values but for the time being I'm just
- 2:42:12going to use this particular uh variable
- 2:42:14from here I'm just going to copy it and
- 2:42:17into my row to there is a task and there
- 2:42:21is a main. yml so this is a a very debug
- 2:42:24message which I just wanted to print and
- 2:42:27here I have created a variable that is
- 2:42:29war and here I'm just going to paste the
- 2:42:31name of my variable that is my secret
- 2:42:34now moving forward what I'll do I'll
- 2:42:35just run this anible Playbook using my
- 2:42:38anible P and for that you just need to
- 2:42:40open the readme file over here and in
- 2:42:42the second point I have written the
- 2:42:43anible Playbook command to execute my
- 2:42:46anible playbook which will use your an W
- 2:42:50and the command is pretty simple over
- 2:42:51here and I'm just going to explain that
- 2:42:53that command also so this is the anible
- 2:42:55Playbook keyword after that you need to
- 2:42:57supply the anible where you will be
- 2:42:59storing the host second you need to uh
- 2:43:03Supply the name of your anible playbook
- 2:43:05so that is anible Vault Playbook yml
- 2:43:08which you can see over here this is my
- 2:43:09anible playbook VA uh
- 2:43:12yml after that you need to supply the
- 2:43:15path of your anible Vault yml using the
- 2:43:19e keyword okay so this is the path where
- 2:43:22I'm storing my anible VA yml which you
- 2:43:25can find over here also so that's the
- 2:43:27important thing and the third parameter
- 2:43:30which you need to supply over here is
- 2:43:32the ask VA password so that you can key
- 2:43:34in or you can enter the password so that
- 2:43:37that you can open that particular anible
- 2:43:39world and you can use the values or the
- 2:43:41secret value which you have store so
- 2:43:44this is the ncble Playbook command which
- 2:43:45I'm just going to execute from my my
- 2:43:48terminal and then after that we're just
- 2:43:49going to see the value which is printed
- 2:43:51onto the console all right so just copy
- 2:43:54this command from here go to terminal
- 2:43:57I'm just going to clear the screen over
- 2:43:59here and paste the command and hit enter
- 2:44:02and this is the first way of running
- 2:44:04your anible playbook with your ncble
- 2:44:06Vault using the ask Vault parameter so
- 2:44:09this is the parameter which I have just
- 2:44:11applied with your with my ncble playbook
- 2:44:13command okay so I'm just going to key in
- 2:44:16my password and hit enter and here you
- 2:44:19can see this is the message uh this is
- 2:44:21the value which I have printed onto my
- 2:44:23console and it is able to fetch the
- 2:44:25value this is a first uh secret sorry
- 2:44:28there is a typo so this is the first
- 2:44:30secret message from my anible mod so
- 2:44:32this is the text I have stored Inside My
- 2:44:34anible Vault yml and now I'm able to
- 2:44:37fetch that particular information onto
- 2:44:40my console using the debug provided by n
- 2:44:43so this is how I'm just going to use the
- 2:44:45secret value inside my anible playbook
- 2:44:48all right so now you have seen the first
- 2:44:50demo where I have created an anible
- 2:44:52Vault and then I am able to run my
- 2:44:54anible plea book using the ask Vault
- 2:44:57pass parameter where I have key in and
- 2:45:00entered My anible Vault password okay so
- 2:45:03before moving forward let's take a few
- 2:45:05more example of our anible vault command
- 2:45:08so I'm just going to clear the screen
- 2:45:09over here and the second command which I
- 2:45:13would like to tell you is to change the
- 2:45:14password of our anible VA so what you
- 2:45:17need to do over here is you need to key
- 2:45:20in first of all anible Vault after that
- 2:45:24you need to type in the keyword that is
- 2:45:26GRE key and after that you need to
- 2:45:28supply the path of your anible vault yml
- 2:45:31which is groups farar and my vault. yml
- 2:45:34and using this command you can change
- 2:45:36the password of your anible Vault and
- 2:45:38you need you just need to hit enter so
- 2:45:41you need to key in your existing
- 2:45:43password and you can set the new
- 2:45:45password over
- 2:45:47here and you need to reconfirm the
- 2:45:50password and once you use this command
- 2:45:53successfully then you will be able to
- 2:45:55change the password of your anible VA
- 2:45:58yml so this is an useful command when
- 2:46:00you want to change the password uh from
- 2:46:03the security reasons all right so till
- 2:46:05now we have seen like how you can key in
- 2:46:07your ncble Vault password to execute
- 2:46:09your ncble playbook and to use your
- 2:46:11ncble vault in the second example what
- 2:46:15I'm just going to do I'm just going to
- 2:46:16create an password file and and inside
- 2:46:19that password file I'm just going to
- 2:46:20store My anible Vault password and that
- 2:46:23password is not going to be a short
- 2:46:25password but this is going to be my base
- 2:46:2764 randomly generated password and these
- 2:46:31passwords are really long and really
- 2:46:33secure because it is randomly generated
- 2:46:35and those are B 64 password so what I'm
- 2:46:38just going to do I'm just going to first
- 2:46:40of all going to create a b 64 password
- 2:46:43file for my ncble Vault so here inside
- 2:46:46my project there is a directory called
- 2:46:48passor file where I'm just going to
- 2:46:50create a password file right now this
- 2:46:52particular uh directory is empty and if
- 2:46:55you take a look onto the r me file how
- 2:46:57to generate this particular password
- 2:46:59file then this is the third point and
- 2:47:01here I have written the command which is
- 2:47:03op SSL R&D for random and I just want a
- 2:47:06base 64 and 2048 bit and I'm just going
- 2:47:10to create my password file with the name
- 2:47:12n Vault and I'm just going to end it
- 2:47:14with the extension. pass for password
- 2:47:17and it is going to be created in inside
- 2:47:19the directory passor file so I'm just
- 2:47:21going to copy this command from here I'm
- 2:47:23just going to head over to my terminal
- 2:47:25and I'm just going to past the command
- 2:47:26and hit enter and it it will just uh
- 2:47:30complete very silently but what you need
- 2:47:32to do you just need to go over here and
- 2:47:34here you can see this Vault file has
- 2:47:36Vault password file has been created and
- 2:47:38if you double click on it then you can
- 2:47:40see this is a b64 randomly generated uh
- 2:47:43password which we are going which we
- 2:47:45will be using uh to open or to edit our
- 2:47:48n ible VA okay so now we have generated
- 2:47:51our password file now what I need to do
- 2:47:53is I need to create a one more Vault
- 2:47:56using that particular password file so
- 2:47:59this is the command which I'm just going
- 2:48:00to use and this command is again same
- 2:48:02anible Vault create and I'm just going
- 2:48:04to create a new yml for My ncble Vault
- 2:48:07using the name My Vault with b64 pass
- 2:48:11yml and I'm just going to supply the
- 2:48:13password file over here because I'm not
- 2:48:15keying in the password manually or by
- 2:48:18from my keyboard I just want to use my
- 2:48:21existing uh password file which I have
- 2:48:24just generated so here I will just
- 2:48:27Supply the path of that particular
- 2:48:28password file uh to my this anible Vault
- 2:48:32and as you can see in the groups bar uh
- 2:48:34there is only one myor wall. yml and
- 2:48:37that wall. yml is uh like I have entered
- 2:48:41the password manually from the keyboard
- 2:48:44but here uh in the next yml I'm I will
- 2:48:46be using my password file which I have
- 2:48:48just created so I'm just going to copy
- 2:48:49this particular command I'm just going
- 2:48:52to head over to terminal I'm just going
- 2:48:53to clear it and I'm just going to paste
- 2:48:56it and hit enter and as you can see uh
- 2:48:59now I'm into the edit mode and here I
- 2:49:01can create my secret so I'm just going
- 2:49:04to go press I from here and I'm just
- 2:49:06going to type in my secret so let's say
- 2:49:09my uh secret uh uh
- 2:49:13from base
- 2:49:1764 pass
- 2:49:19file so this is the variable and I'm
- 2:49:21just going to key in my text message uh
- 2:49:24text
- 2:49:26message uh from base
- 2:49:3064 I'm just going to type in base 64
- 2:49:34VA and this is just a randomly text
- 2:49:37message I'm just going to key in and
- 2:49:40after that save and
- 2:49:42quit so now what we have done we have
- 2:49:44created a password file and using that
- 2:49:46password file we have created an n fault
- 2:49:50so next thing what I'm just going to do
- 2:49:52I'm just going to use that particular
- 2:49:54debug message inside my ncble fbook to
- 2:49:57print the value of that particular
- 2:49:59variable which I have just created using
- 2:50:01the anible Vault so here's a read me
- 2:50:04file and I'm just going to run my ncble
- 2:50:06playbook but this time I'm just not
- 2:50:08going to enter my password manually but
- 2:50:10I'm just going to use my password file
- 2:50:12to run my anible playbook so this is the
- 2:50:15Playbook command which is anible
- 2:50:17Playbook uh keyword after that you need
- 2:50:19to supply the flag inventory and Supply
- 2:50:21the host file where you are storing the
- 2:50:23host information the name of your
- 2:50:25playbook which is ncble Vault yml and
- 2:50:28after that you need to supply uh the
- 2:50:31Vault file path which is this one which
- 2:50:33is a new one which I have just created
- 2:50:35and after that you need to supply the
- 2:50:37password file over here and you should
- 2:50:39provide the correct path of your
- 2:50:41password file okay so I'm just going to
- 2:50:44copy this command from here go to my
- 2:50:47terminal and and I'm just going to paste
- 2:50:50it over here and hit enter and here you
- 2:50:53can see this is the message which I
- 2:50:55printed onto my console using the debug
- 2:50:58and this is the text message which we
- 2:51:00have just keying in into our new andil
- 2:51:03VA and remember I have not entered My
- 2:51:07anible Vault password manually but
- 2:51:09instead I have just supplied my password
- 2:51:11file as a parameter so this is another
- 2:51:14way to uh like store your password and
- 2:51:17uh into the password file and that
- 2:51:19password file is pretty strong because
- 2:51:21that is a b 64 randomly generated
- 2:51:24password string the third one which we
- 2:51:26going to take a look is to export the
- 2:51:28path of your password file so you have
- 2:51:30already generated a password file but
- 2:51:32what you're going to do you're just
- 2:51:34going to export the path into the
- 2:51:36environment variable and here into the
- 2:51:39readme file you will find the
- 2:51:41environment variable name that is anible
- 2:51:44VA password file so that's the
- 2:51:46particular uh variable name you need to
- 2:51:48keep in and Export into the environment
- 2:51:50variable and once you export into the
- 2:51:52environment variable then you don't need
- 2:51:54to even Supply the path of your password
- 2:51:57file you just simply run your anible
- 2:51:59playbook and anible Playbook will
- 2:52:01resolve that environment variable which
- 2:52:03is this one and it will find the path of
- 2:52:06the password file and it will use that
- 2:52:08password file to supply that password to
- 2:52:10our anible Playbook so which is a more
- 2:52:13neater approach uh while handling your
- 2:52:16anible playbook and anible wallet so in
- 2:52:18this readme file you will find a command
- 2:52:20to export your anible uh password file
- 2:52:23path and here remember this is the
- 2:52:26keyword which you need to keep uh keep
- 2:52:29the same name which is anible Vault
- 2:52:30password file because that is an
- 2:52:32environment variable and after that this
- 2:52:34is the particular path from here uh till
- 2:52:37your password file uh which you can see
- 2:52:39over here so this is the complete
- 2:52:41password file path uh so this path will
- 2:52:44change based on your local workspace
- 2:52:46setup so this is my current workspace
- 2:52:48and this is the current path for my uh
- 2:52:50for my local uh development setup but
- 2:52:53just change this path according to your
- 2:52:55password file path so I'm just going to
- 2:52:57copy this command from here and head
- 2:53:00over to my terminal and I'm just going
- 2:53:02to clear the screen and I'm just going
- 2:53:04to paste the command over here and we
- 2:53:08can also confirm by running the Eco
- 2:53:10dollar and the variable name command so
- 2:53:13that we have exported that particular
- 2:53:15variable successfully or not so here you
- 2:53:17can see the uh environment variable has
- 2:53:19been exported successfully the next
- 2:53:22thing which I'm just going to do I'm
- 2:53:23just going to run my anible playbook and
- 2:53:25this time I'm just not going to supply
- 2:53:28any manual password using the ask B
- 2:53:30password parameter or neither I'm just
- 2:53:32going to supply the password file path
- 2:53:35I'm just going to Simply run my ncble
- 2:53:37playbook so I'm just going to clear the
- 2:53:39screen and I'm just going to paste the
- 2:53:41command over here and if you take a look
- 2:53:43onto the command so this is the command
- 2:53:45uh here I have supplied the inventory
- 2:53:47after that this is The anible Playbook
- 2:53:49command and after that the Vault file
- 2:53:52yml which I'm just going to use it and
- 2:53:54after that I have not specified the ask
- 2:53:56VA password parameter for manually
- 2:53:58entering the password and neither I have
- 2:54:00specified my password file path so I'm
- 2:54:04just going to Simply Supply My Vault so
- 2:54:06that it can understand which Vault I
- 2:54:08want to use and after that I'm just
- 2:54:10going to hit enter and here you can see
- 2:54:13our n Playbook has started and here you
- 2:54:16can see this is the message it has fed
- 2:54:18from from our ncble world so this is
- 2:54:21another way uh to run your ncble
- 2:54:23playbook and to export the path of your
- 2:54:26password file into the environment
- 2:54:28variable so this was a very small
- 2:54:30demonstration on how to use your anible
- 2:54:32Vault inside your anible playbook and
- 2:54:34you can use either of the three ways
- 2:54:36which I have mentioned into this lab
- 2:54:38session uh I'll put down the GitHub
- 2:54:40repository link into the description
- 2:54:42section along with the readme file and
- 2:54:45sometimes I also create a blog post on
- 2:54:46the similar lab session so if you don't
- 2:54:49find these read me file inside the
- 2:54:51GitHub repository then I'll also put the
- 2:54:54blog post link of my blog where I will
- 2:54:56mention all the commands which I have
- 2:54:58used for creating the anible F if you
- 2:55:01have any question or feedback then
- 2:55:02please put down into the comment section
- 2:55:04those are really appreciated and do
- 2:55:06follow this channel for the similar
- 2:55:08content on devops and uh U there are
- 2:55:11many SS I have also planned in future so
- 2:55:14see you into the next session of our
- 2:55:16devop still then take care and bye-bye
- 2:55:19welcome to the last part and in this
- 2:55:21chapter we are going to take a look like
- 2:55:23how I use anible Playbook to deploy my
- 2:55:26own website which is J hook.com here you
- 2:55:28can see this is the blog which I have
- 2:55:30been hosting for a quite some time and
- 2:55:32it is registered on a domain J hook.com
- 2:55:34so this is the blog which I have been
- 2:55:36writing on a various devops topic but
- 2:55:39this particular blog is uh using the
- 2:55:41service provided by a site ground
- 2:55:43hosting so this is the hosting provider
- 2:55:45where I'm hosting my blog so I have
- 2:55:48already purchased this domain and then I
- 2:55:50have registered this domain with this
- 2:55:51site ground hosting provider and here
- 2:55:54you can see this is the dashboard of my
- 2:55:56uh particular blog where I manage the
- 2:55:58deployment of my whole blog before I
- 2:56:00walk you through the various options
- 2:56:02available onto this s ground hosting and
- 2:56:04how I am hosting this blog and how I am
- 2:56:07uploading the files to update my blog
- 2:56:09post it is really important for you to
- 2:56:12understand that how this blog works so
- 2:56:14first of all this blog is not a
- 2:56:17WordPress blog it is a static blog what
- 2:56:19does it mean by a static blog so this
- 2:56:21blog is completely written in markdown
- 2:56:24language as well as the pages which you
- 2:56:26see are just the simple HTML Pages there
- 2:56:29is no database running in the behind the
- 2:56:31scene or in the background so here onto
- 2:56:33the screen you can see this is the
- 2:56:35GitHub repository where my whole blog is
- 2:56:37hosted not hosted but I'm maintaining
- 2:56:39onto my GitHub repository so here you
- 2:56:42will see uh this is the directory uh or
- 2:56:45the directory or the folder which I have
- 2:56:46created onto my GitHub repository and
- 2:56:49there are various options over here but
- 2:56:51I'll walk you through like how I write
- 2:56:53my blog how I test my blog post and how
- 2:56:56I run locally so for that what I use is
- 2:56:59I use Hugo static uh website generator
- 2:57:02so if I go to the Google over here and
- 2:57:05if I search for Hugo static site
- 2:57:10generator then this is the first option
- 2:57:13you will get so this is the framework
- 2:57:15which I'm using this is an open source
- 2:57:17framework which you can install onto
- 2:57:19your local system and you can also start
- 2:57:22uh building your own blogs so this is
- 2:57:24the framework which I'm using uh for my
- 2:57:26own blog development and writing the
- 2:57:29various blog post okay so first thing
- 2:57:31first like how does it work so if you go
- 2:57:34back to the intellig so this is the
- 2:57:36GitHub repository where all of my code
- 2:57:39recites for my blog so what I do
- 2:57:41generally is I just start my Hugo server
- 2:57:44so here if I go to the terminal I'll
- 2:57:46just open in a window mode uh let me
- 2:57:50view mode change it to the Window mode
- 2:57:52okay so I'll just go back to the
- 2:57:53directory and yeah this is the correct
- 2:57:56directory where I'm in right now so the
- 2:57:58command which I use it uh remember you
- 2:58:00need to install the Hugo onto your local
- 2:58:02system to make it work okay so I'm
- 2:58:04assuming that you have already installed
- 2:58:06the Hugo and after that I just simply
- 2:58:08run the command Hugo
- 2:58:10ser and here you can see it is running
- 2:58:13on a local host 13313 port and if I go
- 2:58:16back to my browser and here if I I type
- 2:58:18Local Host 1313 and here you can see uh
- 2:58:21this is the blog uh which is running
- 2:58:23onto my local system so here I make the
- 2:58:26changes I verify the changes and once
- 2:58:28I'm satisfied with my blog post then I
- 2:58:30run the anible Playbook which generally
- 2:58:32copies the HTML to my side ground
- 2:58:35hosting server so that's basic uh thing
- 2:58:38which I do behind the scene when I'm
- 2:58:40writing the various blog post so let's
- 2:58:42start by making a small change first
- 2:58:45local onto our system test that change
- 2:58:47and then we will see how we can use the
- 2:58:49ncble Playbook to deploy this website or
- 2:58:51update this website onto my site site
- 2:58:54ground hosting server okay so here I'll
- 2:58:56go back to my intellig and here are some
- 2:59:00of the directories which I have created
- 2:59:01and I'll just give you a little brief
- 2:59:03about like how I uh structured my uh
- 2:59:06various blog post topic so here you will
- 2:59:08find a Content directory and in the
- 2:59:10content directory you will find a post
- 2:59:12directory and inside the post I have
- 2:59:14created a various directory where I keep
- 2:59:16on writing the various blog posts so for
- 2:59:18example anible AWS devop stalker GitHub
- 2:59:22so these are the various categorization
- 2:59:24which I have done so let's take a look
- 2:59:26onto the nple because the latest post
- 2:59:28which I see is this one which I have
- 2:59:30written on September 19th last year I
- 2:59:32have not been active on this blog but
- 2:59:35let's take a look uh so here this is the
- 2:59:37uh markdown file which I generally
- 2:59:39create for my writing my blog so uh this
- 2:59:42is a markdown uh structure which you
- 2:59:45need to follow for writing this blog
- 2:59:47post I I know it it might look
- 2:59:49complicated for you but if once you get
- 2:59:51familiar with using the markdown then
- 2:59:53it's really easy to manage your blog
- 2:59:55post and you can write it from anywhere
- 2:59:57and you don't need any Hy fancy tool to
- 3:00:00manage your blog you just need a editor
- 3:00:02I'm using intellig you can use Sublime
- 3:00:04notepad++ and you can manage your blog
- 3:00:08anyway so what I'm just going to do over
- 3:00:10here is I'm just going to change a few
- 3:00:11things over here so let's see n Handler
- 3:00:14example real world use case and example
- 3:00:17so here I will remove the question mark
- 3:00:19I'll save it and last modify so I'll
- 3:00:22change the state uh I'll change it to
- 3:00:24something uh let's say
- 3:00:2724 and make it March and uh make it
- 3:00:31let's say what's the date today 6th of
- 3:00:34March okay and I think U that's the
- 3:00:38small change which I have done it so
- 3:00:40let's save this file and go back to your
- 3:00:42browser just refresh it and here you can
- 3:00:44see this question mark is gone from here
- 3:00:46if you click on this block post and here
- 3:00:48you can see the last modified date has
- 3:00:50been updated to 6th of March okay so
- 3:00:53this is the modification we have done
- 3:00:55and we are able to verify this change
- 3:00:58okay now the next thing is I'll show you
- 3:01:00how I generate the HTML file and here
- 3:01:03you can see this whole uh block post is
- 3:01:06still into markdown file which you can
- 3:01:08see it is ending with the file. MD which
- 3:01:11is a markdown extension so using this uh
- 3:01:14markdown file we are just going to
- 3:01:16generate an HTML page and that HTML page
- 3:01:19we are just going to copy it to the site
- 3:01:21ground server now how to generate the
- 3:01:23HTML page using the markdown which I
- 3:01:26have just updated so for that we are
- 3:01:28going to use the Hugo command utility
- 3:01:30because I have already shown you like I
- 3:01:32have already installed the Hugo onto my
- 3:01:34local system so here onto the terminal
- 3:01:37what I'll do I'll just go I'll clear the
- 3:01:39screen over here and first thing the uh
- 3:01:42whenever I generate the HTML file then
- 3:01:45it will generate a public folder over
- 3:01:47here so here you can see there is no
- 3:01:49public folder which you can see and in
- 3:01:50that public folder it is going to
- 3:01:52generate all the HTML file after passing
- 3:01:55the markdown file okay so let's go back
- 3:01:58over here uh onto my terminal I'll just
- 3:02:01open the terminal over here and you just
- 3:02:03need to run the command Hugo and it will
- 3:02:06automatically read the all the
- 3:02:08directories where markdown file is
- 3:02:10present and then it is going to process
- 3:02:12it and generate the static HTML file for
- 3:02:14me so here you can see this is the
- 3:02:16output and it has processed so many
- 3:02:19files and these are the images because I
- 3:02:21have copy pasted uh some of the images
- 3:02:24into my blog post as well so these are
- 3:02:25the stats which it has passed and here
- 3:02:29you can see there are 295 Pages which
- 3:02:31has passed and if you go over here then
- 3:02:34you will see a public file over here
- 3:02:36public folder over here and inside this
- 3:02:38public folder you will file all find all
- 3:02:40the HTML for all the blog post so here
- 3:02:43you can see this is a really long list
- 3:02:45because I have posted quite a lot of
- 3:02:47post onto my my blog so all the pages
- 3:02:49are all available over here and if you
- 3:02:51open any of the page let's say I open
- 3:02:54this one then you will see a index.html
- 3:02:57page and if you'll open this one then
- 3:02:59you will find all the blog post in the
- 3:03:01form of HTML so this is how I write my
- 3:03:05markdown uh blog post and then I
- 3:03:07generate the HTML page so this is the
- 3:03:10basic setup for my uh blog and this is
- 3:03:13how I write and generate the HTML in the
- 3:03:16next uh step we are going to take a look
- 3:03:18like how I have written my anible
- 3:03:21playbook to copy this HTML this public
- 3:03:23folder to my site ground hosting server
- 3:03:26okay so let's recap so here is my laptop
- 3:03:29here I have writing the markdown file
- 3:03:32and which markdown file I'm paring using
- 3:03:34the Hugo and Hugo is generating me the
- 3:03:36HTML pages so that's a very basic setup
- 3:03:39which I have onto my local laptop now
- 3:03:42the next thing is how to copy that
- 3:03:44particular file to uh my remote server
- 3:03:47which which is a static ground uh static
- 3:03:49ground uh hosting server so here you can
- 3:03:52see this is my laptop on the left hand
- 3:03:54side which has a private key so I need
- 3:03:57to generate uh as such key one is the
- 3:04:00private key and one is the public key so
- 3:04:03I'm just going to generate that key I'm
- 3:04:05just going to keep the private key on my
- 3:04:07laptop and the public key I'm just going
- 3:04:09to keep onto my site ground server I'm
- 3:04:12just going to show you how to generate
- 3:04:13that key but just understand this
- 3:04:15concept so here I will keep the private
- 3:04:17key with key with me that is only
- 3:04:19available for me and the public key onto
- 3:04:21my side ground server and after that we
- 3:04:24are going to use this SSH key uh to
- 3:04:27communicate with my side ground server
- 3:04:29and using this private key I'm just
- 3:04:31going to copy the HTML file inside my
- 3:04:34site ground hosting server and those
- 3:04:36files are going to be my HTML file which
- 3:04:39I have just generated now let's take a
- 3:04:41look onto to the site ground and how the
- 3:04:43files are visible over there so if I go
- 3:04:45to my browser over here go to the site
- 3:04:48ground so this is my console of my
- 3:04:50website where I'm hosting my website so
- 3:04:53here you just need to go to site over
- 3:04:55here and here you will find a file
- 3:04:58manager so here in the file manager you
- 3:05:00will find uh the public HTML directory
- 3:05:04which you can see and here in the
- 3:05:05public. HTML you will find all the HTML
- 3:05:08pages so if I open this one and here you
- 3:05:12can see the index.html page so these are
- 3:05:14the files which I generally copy from my
- 3:05:17local machine to my site ground hosting
- 3:05:20server okay but how do I do that so what
- 3:05:23I do is like this is a flow which I have
- 3:05:26implemented using the N so I hope now
- 3:05:29the SSH key part is clear to you I'm
- 3:05:32copying HTML file from my local laptop
- 3:05:34to my site ground hosting server okay so
- 3:05:37this is the part I hope you're clear
- 3:05:39with that the next thing is how I'm
- 3:05:41copying this file I'm not copying one
- 3:05:44file by one file I'm just generating the
- 3:05:47file then I'm creating a z file then I'm
- 3:05:49uploading the zip file to the side
- 3:05:51ground server which I'm just going to
- 3:05:52show to you so this is my laptop here
- 3:05:55I'm generating the HTML file after that
- 3:05:57I'm creating a zif file and that zip
- 3:06:00file I'm just putting it onto or I'm
- 3:06:02uploading it onto my S ground hosting
- 3:06:04server and once I upload that Zev file
- 3:06:06then I'm just going to extract again all
- 3:06:09the HTML files out of it and this is how
- 3:06:12I do the deployment of my website onto
- 3:06:14the site ground using the N Okay so that
- 3:06:17part is clear to you now coming back to
- 3:06:20the point I need SSH keys I need a
- 3:06:23private key and I need a public key so
- 3:06:25that our whole uh uh communication is
- 3:06:28secured between the side ground on my
- 3:06:30and also my laptop okay so I'm just
- 3:06:32going to open the terminal over here so
- 3:06:35let's open the terminal over here and in
- 3:06:38the terminal you can just type the
- 3:06:39command SSH key gen and it will generate
- 3:06:43the public key and the private key for
- 3:06:44you so here as soon as you enter the SS
- 3:06:47keys in onto your terminal if you're
- 3:06:50using the Windows system then I would
- 3:06:52highly recommend to use git bash because
- 3:06:54that's where you can run these command
- 3:06:56or you can use the wsl2 which is like a
- 3:07:00uh sub Linux subsystem which you can
- 3:07:02install onto to your laptop uh if you're
- 3:07:05using the windows so I would highly
- 3:07:07recommend to use those so that you can
- 3:07:09generate the SSH keyen I'm using the uh
- 3:07:12Mac so here I have the terminal so here
- 3:07:14I can run these kind of a command so it
- 3:07:16will generate the key onto this
- 3:07:18particular directory so keep in mind uh
- 3:07:20just always remember this is the path
- 3:07:22where you will get the keys okay so what
- 3:07:25I'm just going to do I'm just going to
- 3:07:27copy this full path and I'm just going
- 3:07:29to put some custom name to my key so I'm
- 3:07:32just going to paste it over here and I'm
- 3:07:34just going to put site uh ground uh demo
- 3:07:39okay and hit enter uh do you like to
- 3:07:42have a pass phras for your SSH key then
- 3:07:45I'm just I'm just going to skip that one
- 3:07:46no I'm just going to Simply hit enter
- 3:07:49okay and now my keys are generated so if
- 3:07:52I go to this particular directory and if
- 3:07:55I run the ls command so I'm just going
- 3:07:57to copy this path clear the path and I'm
- 3:08:01just going to run the command LT and I'm
- 3:08:04just going to paste the
- 3:08:06path so here you can see this is
- 3:08:09our private key and this is Pub is going
- 3:08:13to be our public key so this is how
- 3:08:16you're just going to generate the keys
- 3:08:18for you and these Keys we are going to
- 3:08:21use to upload our HTML Z file okay I
- 3:08:25just wanted to show you the key because
- 3:08:27the keys I have already generated and I
- 3:08:29have already set up for my site ground
- 3:08:31hosting so I'm not going to change those
- 3:08:33thing but all the steps which I'm
- 3:08:36showing to you is exactly the same this
- 3:08:37is how you just going to generate the
- 3:08:39key and then we are going to use those
- 3:08:41keys to uh enable the communication
- 3:08:43between the server and our lab okay so
- 3:08:45now let's talk like where I have
- 3:08:47configured the public key onto my side
- 3:08:50ground server so here you can see this
- 3:08:51is the public key which is I have put it
- 3:08:54mentioned over here so I need to set up
- 3:08:56that particular key so if you go to my
- 3:08:58site ground hosting go to dashboard and
- 3:09:02here if you go to the tools I'm saying
- 3:09:05it should be security and here you can
- 3:09:08see this is a security go to SSL
- 3:09:11manager and uh in the SSL manager U wait
- 3:09:15for a second sorry it's under Dev
- 3:09:19and here you will find the SSH key
- 3:09:21manager so in this section you will find
- 3:09:23the keys so here you can see uh here I
- 3:09:26have already uh uploaded this key this
- 3:09:28is our SSH RSA key so this key I have
- 3:09:32already uploaded over here so this is my
- 3:09:35public key which I have just uploaded to
- 3:09:37the site ground and there are few more
- 3:09:40details which you need to keep in mind
- 3:09:42so this is the username uh because you
- 3:09:46have the key but you need a username to
- 3:09:48login into your uh site ground server so
- 3:09:51here I'm this is the username for that
- 3:09:54Linux system and this is the port where
- 3:09:56I will be doing the communication or
- 3:09:58this port is open for performing this
- 3:10:00kind of activity since I'm using sround
- 3:10:03so it is very specific to site ground
- 3:10:06but if you're using any other Linux
- 3:10:08server or Linux hosting then you should
- 3:10:10get a username something from that Linux
- 3:10:13hosting and you should check the port
- 3:10:15number which they are allowing you to
- 3:10:17use so these are the few details which
- 3:10:19you need to keep in mind okay and uh
- 3:10:22this key SSH Keys concept is pretty much
- 3:10:25common irrespective of any of the
- 3:10:28hosting Services you are using so just
- 3:10:30check with them like do they support or
- 3:10:32do they have this feature enabled for
- 3:10:34you or not if they have enabled it then
- 3:10:36just simply upload the public key over
- 3:10:38here okay and how to do that sometime
- 3:10:42you can even import the key so you just
- 3:10:44need to paste the content over here so
- 3:10:46if you see over here
- 3:10:49um so here if I clear this directory and
- 3:10:53if I go over here and I type site ground
- 3:10:56demo. Pub so uh not lslt it should be
- 3:11:01cat
- 3:11:03actually and here you can see you can
- 3:11:05just simply copy this content from
- 3:11:09here and go to your site ground hosting
- 3:11:12and paste it over here it is that simple
- 3:11:15so you have just uploaded the public key
- 3:11:17onto your whatever hosting you're using
- 3:11:20so this is that simple okay so now uh
- 3:11:23this is our SSH key manager I'm not
- 3:11:25going to use this one and here we
- 3:11:27already have those keys with us okay now
- 3:11:30I have explained you the whole setup and
- 3:11:32how we are going to implement these
- 3:11:34things and what are the prerequisites
- 3:11:36which is needed to achieve this thing so
- 3:11:39now I will explain to you like how I
- 3:11:41have written the anible Playbook to
- 3:11:43implement the whole scenario okay so in
- 3:11:45the same uh reposit itory where I'm
- 3:11:48having my blog uh I have created anible
- 3:11:51Playbook directory and here in the
- 3:11:53anible Playbook I have created a J hook
- 3:11:55Playbook yml okay so this is the task
- 3:11:58which I have created and the task I have
- 3:12:00created a role which is Jook So if you
- 3:12:02go over here and one more thing I
- 3:12:04mentioned the username so I'm using this
- 3:12:06username if you take a look this is the
- 3:12:08username and if you go back then you
- 3:12:11will find the same username over here
- 3:12:13which is this one so that's why I said
- 3:12:15like you just need to check with them
- 3:12:16like what kind of a username they are
- 3:12:18allowing you to use so this is the
- 3:12:20username which I'm using so I'm running
- 3:12:22this whole Playbook with this particular
- 3:12:24remote user and this is the task which I
- 3:12:26have created so let's take a look onto
- 3:12:28the task so this is the J hook uh go to
- 3:12:31inventory not inventory go to roles go
- 3:12:34to Jook go to task and there is a main.
- 3:12:37yml okay so this is the U main Playbook
- 3:12:40which is responsible for copying the
- 3:12:43content all right so first thing uh this
- 3:12:47is the simple task which is just
- 3:12:49outputting the path which is PWD the
- 3:12:51current
- 3:12:53path second it is running the Hugo
- 3:12:55command it is just a simple Hugo command
- 3:12:57to generate the HTML content so if I uh
- 3:13:02if you remember then I have shown you
- 3:13:04like this is the command which I have
- 3:13:05run previously so this is the Hugo
- 3:13:07command which I have run so which has
- 3:13:09generated the basic HTML Pages for us in
- 3:13:13the public directory which is uh
- 3:13:17this one where it is this one okay so
- 3:13:20I'm just simply running the Hugo command
- 3:13:22so that I can generate the HTML Pages
- 3:13:24for my block posts after that uh this is
- 3:13:29simple debug I have written just for
- 3:13:30debugging whether it is on a correct
- 3:13:33path or not second here I'm running the
- 3:13:36command to compress the directory so I
- 3:13:39just wanted to compress the public
- 3:13:41directory which is this directory so
- 3:13:44here this is the path of that uh sorry
- 3:13:47this is just a name but here I'm just
- 3:13:49putting the path so this is the path so
- 3:13:51this is the project path and if you can
- 3:13:53see this variable so this variable I
- 3:13:55have defined into roles and if you go to
- 3:13:58vs and this is the main do VAR so this
- 3:14:00is the project path I'll just go to I'll
- 3:14:03just wrap it
- 3:14:05around and here you can see this is the
- 3:14:07uh location where my current project is
- 3:14:10available onto my Mech uh laptop so this
- 3:14:14is the exact path where my uh files are
- 3:14:16located
- 3:14:17so this is using the project path and
- 3:14:19there it is looking for a public
- 3:14:21directory and then it is looking for all
- 3:14:22the content and in the destination it is
- 3:14:25again using the same project path and
- 3:14:27here it is creating a zip file name and
- 3:14:30what is the zip file name variable it is
- 3:14:31jhop do zip okay so here you can see uh
- 3:14:35we have the public directory but I have
- 3:14:37not run the Playbook so there is no zip
- 3:14:40uh J hook. up which has been created
- 3:14:42I'll show you once I run this Playbook
- 3:14:44okay so here uh
- 3:14:47here till this part we are just creating
- 3:14:49the Z file so if you take a look onto
- 3:14:52our presentation once again so here uh
- 3:14:56HTML has been generated and now we have
- 3:14:58created a zip using the zip uh anible
- 3:15:01task okay uh here so we have completed
- 3:15:05this many task next we are just doing
- 3:15:08the copy operation so here it is using
- 3:15:11the path like project path and the zip
- 3:15:14file name which is this one okay so it
- 3:15:17is using this complete Z file and it is
- 3:15:20uploading it to the J hook.com which is
- 3:15:22our site ground hosting and this is the
- 3:15:24destination directory okay and here is
- 3:15:26the destination directory which I have
- 3:15:27defined so if you go to over here and
- 3:15:30this is the destination directory so
- 3:15:31which you can see which is home this is
- 3:15:34the username uh of my site ground
- 3:15:37hosting and this is the path which is J
- 3:15:40hook.com picore HTML and if I show you
- 3:15:43over here then if I go
- 3:15:47uh to file manager and if I go here you
- 3:15:51can see this is the path actually I'm
- 3:15:54inside if you go here then here you can
- 3:15:56see this is the path which is uh where I
- 3:15:58need to upload it job.com public HTML
- 3:16:02and which
- 3:16:03is this
- 3:16:05one exactly okay and let's go back to
- 3:16:10the task uh task yml once again and
- 3:16:13after that I'm just after copying that
- 3:16:16particular file
- 3:16:17uh if I take a look over here so here I
- 3:16:20just copied it the zip file over there
- 3:16:22after that I have written extract task
- 3:16:25so this is going to extract that
- 3:16:27particular Z file so here it is just
- 3:16:29going to extract and generate or uh
- 3:16:32extract the HTML file out of the C file
- 3:16:35and here this is the task which I have
- 3:16:37written for that one and once it is
- 3:16:39extracted then it is going to remove
- 3:16:41that particular Z file then this Z file
- 3:16:44from the remote server is going to
- 3:16:46remove so this is the simple Playbook
- 3:16:48which I have written to automate the
- 3:16:51deployment of my blog post onto uh my
- 3:16:55site ground hosting and one key thing uh
- 3:16:58I forgot to tell you like where is my
- 3:17:00private key I have shown you like how to
- 3:17:02upload the public key to the sideg
- 3:17:04ground hosting but where is my private
- 3:17:06key so in the same anible Playbook
- 3:17:08directory in the inventory you will find
- 3:17:11I have used this private key which is J
- 3:17:14hook this is our private key which is
- 3:17:16I'm only keeping it over here although I
- 3:17:18have copied this public key also but I'm
- 3:17:21not I'm not using this public key
- 3:17:23anywhere I just copied it so that if I
- 3:17:26uh if I change my laptop if I format my
- 3:17:29laptop then I have a copy of that
- 3:17:31particular key I don't need to
- 3:17:33regenerate that key so that's the
- 3:17:35purpose I have kept it over there and in
- 3:17:37the host file if you take a look uh if I
- 3:17:41go and show you once again so this is
- 3:17:43the uh sorry it should be it should be J
- 3:17:46hook uh I have just changed the host
- 3:17:48name so here is the name of my Host this
- 3:17:52is the uh path of my private file and
- 3:17:56this is the port where it will be
- 3:17:58communicating okay so this is the host
- 3:18:01which is side ground Host this is the
- 3:18:03path of my private file a private SSH
- 3:18:06key and this is the port where it will
- 3:18:08do the communication so this is the
- 3:18:10defination or this is the configuration
- 3:18:12for my host file for running this
- 3:18:15anible okay
- 3:18:17now we have seen everything now we need
- 3:18:19to run this Playbook okay and if I go
- 3:18:23back to my website uh refresh this page
- 3:18:26over here and here you can see this uh
- 3:18:29uh question mark is still there and if
- 3:18:31we check the last modified that then it
- 3:18:34is 19th September
- 3:18:362023 okay but on local if you check the
- 3:18:39same thing then it is there is no
- 3:18:41question mark and the modified date is
- 3:18:436th of March okay so let's update the
- 3:18:46whole uh let's run the Playbook and
- 3:18:48update the whole uh block post okay go
- 3:18:51back to your uh terminal over here in
- 3:18:54the ID and uh go I'll clear this
- 3:18:59[Music]
- 3:19:00one then I'll go to the anible directory
- 3:19:04and here what I do is I generally uh
- 3:19:06written the command into that yml so
- 3:19:08which is jhub dot this is the Playbook
- 3:19:11command which I generally run so this
- 3:19:13I'll just copy this command I'm just
- 3:19:15going to explain to you also that
- 3:19:17one and I'm just going to paste it so
- 3:19:21this is the simple command which is n
- 3:19:23Playbook then there is a inventory and
- 3:19:25inventory I'm specifying the host file
- 3:19:27the host location of the file and the
- 3:19:29name of the Playbook which I'm just
- 3:19:31running which I have just explain to you
- 3:19:33okay it is that simple and after that
- 3:19:35you just simply hit
- 3:19:38enter and here you can see it started to
- 3:19:42uh create uh the public HTML that it is
- 3:19:45going to now it is compressed in the
- 3:19:47file now it is copying the content to
- 3:19:50side
- 3:19:54ground and this is the
- 3:19:57host and now it is extracting the zip
- 3:20:00file onto the side ground at this
- 3:20:02particular
- 3:20:03location and after that it is removing
- 3:20:07this particular Z file over here so it
- 3:20:09has finished this task okay and if you
- 3:20:12take a look over here then here you can
- 3:20:14see now the Z.Z file has been created
- 3:20:17over here okay which was not present
- 3:20:20previously so now my content is updated
- 3:20:23onto my website so if you go back over
- 3:20:27here uh and I'll close this Local Host
- 3:20:30if you see take a look this is Local
- 3:20:31Host I'm just going to close this one
- 3:20:33I'll just close this one also and I'll
- 3:20:36just go to the dashboard and over here
- 3:20:39so if I refresh this page uh right now
- 3:20:42so it will not show the changes because
- 3:20:44there are some caching which is
- 3:20:46implemented from side ground so I need
- 3:20:48to delete the whole caching for my
- 3:20:50website so that it can show the latest
- 3:20:52changes okay so I'll go to the site
- 3:20:55ground and uh I think it should be into
- 3:20:58the speed go to
- 3:21:01caching go to Dynamic caching and then
- 3:21:04clean this flush the
- 3:21:06cachier and now the cachier has been
- 3:21:08flushed so these are some custom
- 3:21:11settings which I learned eventually when
- 3:21:13I started working more with my blog post
- 3:21:15and hosting uh uh side ground
- 3:21:18hosting now uh the caching has been
- 3:21:21cleaned and I'll just refresh this page
- 3:21:23once again and here you can see the
- 3:21:25question mark is gone and the last
- 3:21:27modified date it shows now the 6th of
- 3:21:29March so this is how I maintain my blog
- 3:21:34post and this is how I uh automated my
- 3:21:37whole deployment because uh what happens
- 3:21:40is like I generally write quite a lot of
- 3:21:43blog post and I modify quite a lot of
- 3:21:45blog post so it's a quite manual thing
- 3:21:47if I write a four or five blog post and
- 3:21:49those blog post has certain images so a
- 3:21:53single blos block post update can
- 3:21:55contains four or five images four or
- 3:21:58five files so I just need to manually
- 3:22:01copy those files if I don't use anible
- 3:22:04so instead of uh doing that task
- 3:22:06manually I just return this anible
- 3:22:08Playbook which just generate everything
- 3:22:11zip it everything and upload it to the
- 3:22:13server and that's how I just automated
- 3:22:16this task and it just take a few clicks
- 3:22:17to run the Playbook and my blog is up to
- 3:22:20dat I hope this uh project will help you
- 3:22:23to understand uh the previous concept
- 3:22:26which you have learned throughout in
- 3:22:27this course and you got a chance to see
- 3:22:30like how I'm using it in a real time so
- 3:22:33if you like this kind of a Content
- 3:22:35that's please considering subscribing to
- 3:22:37this Channel and also please check out
- 3:22:39the premium membership program also
- 3:22:41which I have just created for you where
- 3:22:44I keep on uploading these kind of
- 3:22:45projects over there as well so keep
- 3:22:48following this channel for more devops
- 3:22:50related topics and see you into the next
- 3:22:53session till then take care and bye-bye
About this transcript
This page contains the full transcript of Ansible Full Course | Zero to Hero by Rahul Wagh, generated from the public captions YouTube serves with the video. The transcript has 40,197 words across 5,422 segments, with the original timestamps preserved so you can click any line to jump to that moment in the embedded player.
What you can do with it
Use the transcript to take notes, quote the speaker, build a study guide, generate a summary with ChatGPT or Claude via the YouTube Summary tool, or export it as a timed subtitle file with YouTube to SRT. You can also re-open it in the transcriber to choose a caption track available on the video.
Free YouTube transcript tool
YouTube2Text is a free YouTube transcript generator — no signup, no daily limit. Paste any YouTube link and get the full transcript instantly, with timestamps, click-to-jump, caption language selection, AI prompts for ChatGPT, Claude, and Gemini, and exports to TXT, SRT, VTT, or Markdown.