YouTube2Text

Ansible Full Course | Zero to Hero — Transcript

by Rahul Wagh · 40,197 words · 5,422 segments · language en · Watch on YouTube

Full transcript

  1. 0:00hello there and welcome to this anible
  2. 0:02course this is Rahul and before we jump
  3. 0:04into our anible course let's take a
  4. 0:06pause over here and take a look onto the
  5. 0:08topics which we are going to cover into
  6. 0:09this particular Series so here I have
  7. 0:12listed all the topic and I will also
  8. 0:14leave the time stamp of each chapter
  9. 0:16into the description section so if
  10. 0:18you're just uh getting started with the
  11. 0:20anible then I would highly recommend to
  12. 0:22go through all this chapter and for
  13. 0:24those who are already familiar with
  14. 0:26these kind of a concept then just check
  15. 0:28the Tim stamp and look for the spefic
  16. 0:30specific chapter uh which you want to
  17. 0:31practice or which you want to learn and
  18. 0:33the last chapter of this inable series
  19. 0:35I'm just going to cover one project
  20. 0:37where I have written my own anible
  21. 0:39Playbook to deploy my own blog so this
  22. 0:42Playbook will help you to understand how
  23. 0:44you can use your concept to create your
  24. 0:46own anible automation so don't miss that
  25. 0:49chapter if you want to really learn like
  26. 0:51how the anible work in real time so
  27. 0:54without further Ado let's start with our
  28. 0:55chapter
  29. 0:57one now back to the important questions
  30. 1:00like what the anible is so anible is an
  31. 1:02open- Source tool which help you majorly
  32. 1:04with the three tasks so the first task
  33. 1:06is uh the software installation so with
  34. 1:09the help of anible you can automate the
  35. 1:11task of installing software onto various
  36. 1:14servers second it can help you to manage
  37. 1:17the server configuration and what does
  38. 1:19it mean so with the help of management
  39. 1:21of a server configuration you can add a
  40. 1:23new configuration you can update a uh
  41. 1:26any existing configuration and even you
  42. 1:28can delete the uh configuration ation of
  43. 1:30a server the third thing and which is
  44. 1:32the most important thing is you can
  45. 1:34deploy your web application or any kind
  46. 1:36of application on a server and you can
  47. 1:39even automate that task using the anible
  48. 1:42All right so I don't want to stuff you
  49. 1:44with a lot of theory about anible and
  50. 1:46why don't we switch to our desktop and
  51. 1:48see a very small Playbook where we will
  52. 1:51try to see like how we can automate the
  53. 1:53installation of a software packages
  54. 1:55using the anible and also we will see if
  55. 1:57we don't have an anible then how we are
  56. 1:59going to install a software package on a
  57. 2:02server so that you can get the
  58. 2:04understanding like if you have a anible
  59. 2:06then how you will automate the task and
  60. 2:08if you don't have the anible then how
  61. 2:10you're going to handle those task so
  62. 2:12let's switch over to my desktop and see
  63. 2:13that small anible Playbook all right
  64. 2:16let's try to understand the scenario
  65. 2:17where you don't have a anible with you
  66. 2:20so how you're going to install the
  67. 2:21software packages so here onto the
  68. 2:23screen if you will see on the left hand
  69. 2:25side I have some script which is like
  70. 2:28installing uh python and creating a
  71. 2:31directory and also installing an Apache
  72. 2:332 server and on the right hand side if
  73. 2:35you'll see this is my remote server with
  74. 2:37an external IP which I have highlighted
  75. 2:40in the red color font so that's the
  76. 2:42remote server where I'm just going to
  77. 2:43execute this command and since I don't
  78. 2:46have an anible with me so what I'm going
  79. 2:48to do I'm just going to use the simple
  80. 2:49SSH method to login into the server and
  81. 2:52execute these commands so that I can
  82. 2:54install python I can install Apache 2
  83. 2:57and also I can create the directory so
  84. 2:59this this is the way I'm just going to
  85. 3:01do if I don't have the anible the next
  86. 3:03thing which I'm just going to show a
  87. 3:05glimpse of a anible Playbook where we
  88. 3:07are just going to automate all this task
  89. 3:09into a single Playbook which is we call
  90. 3:12it as a anible Playbook all right moving
  91. 3:14to the anible part so this is the
  92. 3:16smallest sensible Playbook which I have
  93. 3:18for this uh particular very short demo
  94. 3:21so I'll start from the top over here so
  95. 3:23here you can see uh this is the first
  96. 3:25task which I have written over here for
  97. 3:27installing the python so here uh one
  98. 3:30disclaimer I would like to give you here
  99. 3:32this is a introductory part here I'm
  100. 3:34just trying to explain the difference
  101. 3:36between if you don't use anible and when
  102. 3:38you use anible so don't try to uh like
  103. 3:41remember everything over here because we
  104. 3:44will take a deep dive look into the each
  105. 3:46file inventory task and the playbooks
  106. 3:49into the letter session and also we will
  107. 3:51take a look on how to install the anible
  108. 3:53also so we will start from that
  109. 3:55particular uh stage where we don't have
  110. 3:57the anible installed onto over system
  111. 4:00here I'm just trying to explain the
  112. 4:02difference between when you don't have a
  113. 4:03anible and when you have a anible so
  114. 4:05what are the changes you will see okay
  115. 4:08so now coming back over here so this is
  116. 4:10the first task which I have written into
  117. 4:12my anible playbook which which will
  118. 4:14install the python onto my uh remote
  119. 4:17server second this is the task for
  120. 4:20creating the directory this is the third
  121. 4:23task for installing the Apache 2 server
  122. 4:25so here you will see the differences so
  123. 4:28if you go back to our present ation deck
  124. 4:30where I have shown you so here you will
  125. 4:31see the oneliner commands so these
  126. 4:34oneliner commands are not
  127. 4:35self-explanatory unless and until you
  128. 4:37know or you have used those command in
  129. 4:39the past so here you will see although
  130. 4:42it is really short and although you can
  131. 4:44uh combine all these commands into a
  132. 4:46single shell script file but it doesn't
  133. 4:49look so intutive if any other developer
  134. 4:52is working on to this bash script then
  135. 4:55he will find a little bit of difficulty
  136. 4:57understanding uh those command because
  137. 4:59those are not so much they don't have
  138. 5:01the description behind them but if you
  139. 5:04take a look over here into the anible
  140. 5:06Playbook so here this is the first task
  141. 5:08here you have the name this name is
  142. 5:10really self-explanatory like what it is
  143. 5:12trying to do here is the second task
  144. 5:15where I'm also writing my own custom
  145. 5:17name like create directory I can explain
  146. 5:20further more like what kind of a
  147. 5:21directory I want to create and here is
  148. 5:23the third task where I'm just saying uh
  149. 5:26explicitly hey I'm trying to install the
  150. 5:28python so this is the main difference
  151. 5:30between the uh when you don't use anible
  152. 5:33and when you use anible all right so
  153. 5:35let's SSH into the server which is
  154. 5:37running remotely and this is my terminal
  155. 5:40over here if you can see and the command
  156. 5:42which I'm just going to run is this one
  157. 5:44so this is my SSH command and this is
  158. 5:46the private key I'm using to SSH uh in
  159. 5:49case if you are having a remote machine
  160. 5:51and you have a username and password
  161. 5:53then you can use the puty also since I'm
  162. 5:56using the Mac machine that's why I'm
  163. 5:57using the SSH command but in case if you
  164. 5:59if you're using the Windows machine then
  165. 6:01you can uh use the putty utility where
  166. 6:03you can just specify the external IP
  167. 6:06your username and password and in case
  168. 6:08if you're having a private key then you
  169. 6:10can just simply add your private key
  170. 6:12over here followed by the username and
  171. 6:15the external IP so this is the way you
  172. 6:17can do the SSH into your remote machine
  173. 6:19but anyways so this is the way I'm just
  174. 6:22going to do the SSH into my uh remote
  175. 6:24machine and this IP is little bit
  176. 6:25different from my initial uh PP which I
  177. 6:28have shown to you because I have started
  178. 6:29a new virtual machine that's why I have
  179. 6:31got the new IP so I'm just going to
  180. 6:34execute this
  181. 6:35command and here you can see I'm able to
  182. 6:37SSH into my remote server all right now
  183. 6:41the next thing which we are going to do
  184. 6:42we are just going to run those command
  185. 6:44manually without using anible so that we
  186. 6:47can analyze like what's the difference
  187. 6:49uh we observe between the without using
  188. 6:52anible and with using anible so uh this
  189. 6:55is the bash script uh which I have
  190. 6:57written over here so I'm just going to
  191. 6:58manually run one by one command onto my
  192. 7:01terminal so the first thing which I'm
  193. 7:02just going to do I'm just going to do
  194. 7:04the appt gate update which is uh for
  195. 7:06updating the package manager of my Linux
  196. 7:09machine since I'm using devian base UB 2
  197. 7:12that's why I'm using the app uh package
  198. 7:14manager so I'm just going to paste the
  199. 7:16command over here and this is the way we
  200. 7:19are just going to update the package
  201. 7:20manager I'm just going to speed up some
  202. 7:22of the
  203. 7:25commands so First Command has been
  204. 7:28executed the next command which I'm just
  205. 7:29is going to run is the install python so
  206. 7:32I'm just going to open the terminal once
  207. 7:33again I'm just going to paste it over
  208. 7:35here so here I just wanted to show you
  209. 7:38uh like if you don't use the anable then
  210. 7:40this is how you are just going to set up
  211. 7:42your server where you're just trying to
  212. 7:44install one package uh one after another
  213. 7:46so here you can see the python version
  214. 7:48is already by default installed so it is
  215. 7:50not going to install the
  216. 7:52python moving further so here I'm just
  217. 7:54going to create the directory so this is
  218. 7:56the command uh I'm just going to paste
  219. 7:58it over here and here I'm just going to
  220. 8:02run the ls command and here you can see
  221. 8:03this is the basic HTTP directory which
  222. 8:05has which has been
  223. 8:07created all right the next thing which
  224. 8:09I'm just going to do I'm just going to
  225. 8:10copy the installation command for Apache
  226. 8:13server I'm just going to head over to my
  227. 8:16terminal over here I'm just going to
  228. 8:17paste the
  229. 8:19command all right so here you can see we
  230. 8:21have installed the Apache server now
  231. 8:24what we need to do is we need to enable
  232. 8:25the Apache so this is the command which
  233. 8:27I'm just going to use so again I'm just
  234. 8:28going to go to ter I'm just going to
  235. 8:30paste the command and hit
  236. 8:32enter and here you can see we have
  237. 8:34started our Apache 2 server the next
  238. 8:37thing which we're going to do we're just
  239. 8:38going to verify the status of a PES so
  240. 8:40I'm just going to run system
  241. 8:43CTL
  242. 8:48[Music]
  243. 8:51uh and here you can see uh the status of
  244. 8:54Apache to server service is green that
  245. 8:56means we have successfully installed the
  246. 8:58Apache to server on to our Linux machine
  247. 9:01okay so now you have seen the manual way
  248. 9:03when we don't have the anible with me
  249. 9:05then this is the way I'm just going to
  250. 9:07install the software packages onto my
  251. 9:09remote server now I'm just going to
  252. 9:11switch over to the anible way where I'm
  253. 9:13just going to run only single Playbook
  254. 9:15and that will install all these packages
  255. 9:18using the anible All right so now we
  256. 9:20have seen the manual way of installing
  257. 9:22the software packages using the bash
  258. 9:24script but now let's uh take a look onto
  259. 9:26the Playbook once again so this is the
  260. 9:28Playbook which have explained to you
  261. 9:30earlier and the name of the Playbook
  262. 9:32which I will be using for running this
  263. 9:34Playbook is VM setup playay book. yml
  264. 9:37this font might be small but uh when
  265. 9:39I'll switch over to terminal then I can
  266. 9:40show you the exact name okay so I'm just
  267. 9:43going to switch to my terminal and this
  268. 9:45is the command which I'm just going to
  269. 9:46run so that starts with the keyword
  270. 9:48anible Playbook after that you need to
  271. 9:51specify the remote host uh which we call
  272. 9:54it as a inventory in anible we will take
  273. 9:56a look uh uh in the letter session for
  274. 9:59the inventory and the host but just to
  275. 10:01keep you uh just to give you a little
  276. 10:03bit brief so this is the name of the
  277. 10:05host file actually that means the remote
  278. 10:08machine and this is the name of the
  279. 10:10Playbook which I was referring to I can
  280. 10:12show you the host file where I have made
  281. 10:13an entry for our remote machine so if
  282. 10:17you go over here so this is the host and
  283. 10:19this is the IP address of my remote
  284. 10:21machine or the remote server so this is
  285. 10:24how uh the basic and simple play look
  286. 10:26like so this is the command which I'm
  287. 10:28just going to execute and you just
  288. 10:29simply need to hit
  289. 10:31enter and if this is the first time you
  290. 10:33are connecting to your remote server
  291. 10:35then it is going to ask are you sure you
  292. 10:36you want to connect you simply need to
  293. 10:38type yes and hit enter and then it will
  294. 10:41take maybe couple of minute or 3 minute
  295. 10:43to complete the Playbook but uh
  296. 10:45meanwhile I can show you some of the
  297. 10:47output which it generate to tell you
  298. 10:50that what task it has finished so here
  299. 10:52you can see it is installing the
  300. 10:56python and here you can see uh the
  301. 10:59status change that means it has
  302. 11:01installed the python the next task which
  303. 11:03it is doing it is creating a directory
  304. 11:06and the third task which it is doing is
  305. 11:08to install the Apache and as soon as all
  306. 11:11the three task has been finished and you
  307. 11:13will see a su a message over here that
  308. 11:16like three changed okay for and you will
  309. 11:19not see any error message that means
  310. 11:21your anible playbook has successfully
  311. 11:23finished and now we can SSH into server
  312. 11:26and verify that it has installed the
  313. 11:28required packages which we have
  314. 11:30mentioned inside our anible Playbook
  315. 11:32okay so I'm I have opened one another
  316. 11:34terminal and here I have mentioned the
  317. 11:36SSH command and the remote IP of my
  318. 11:39remote server I'm just going to Simply
  319. 11:41hit enter and here I'm into my remote
  320. 11:43machine and here we can verify one by
  321. 11:45one so first of all I'm just going to
  322. 11:47run the ls command to verify the
  323. 11:48directory and here you can see this
  324. 11:50directory has been created the first
  325. 11:53thing uh which I forgot to check is the
  326. 11:55python command so I'm just going to run
  327. 11:57the command Python 3 version and here
  328. 12:01you can see python has been installed
  329. 12:03the third thing which I need to verify
  330. 12:04is the Apache 2 server so I'm just going
  331. 12:06to run the system CTL
  332. 12:10status and Apache 2 and here you can see
  333. 12:15it has uh installed the Apache 2 also so
  334. 12:18that means our anible Playbook has
  335. 12:20finished the task and it has
  336. 12:22successfully install all the three
  337. 12:24things which we have asked all right so
  338. 12:26now we have taken a look onto the very
  339. 12:28small demo of anible and I really felt
  340. 12:30that demo is really essential for you to
  341. 12:33understand the anible better now in the
  342. 12:35next session we will take a look like
  343. 12:37why anible is called agentless and also
  344. 12:40we are going to take a look like how to
  345. 12:41install anible onto your local machine
  346. 12:44so that you can uh run the anible
  347. 12:46Playbook and you can just make a
  348. 12:48software installation change config and
  349. 12:50deploy your web application so those we
  350. 12:53are those are the topics which we are
  351. 12:54going to cover into the next
  352. 12:57session welcome to the second part of
  353. 12:59the anible series and in this session we
  354. 13:01are going to take a look like why anible
  355. 13:04is called agentless and later we are
  356. 13:06going to take a look how to install
  357. 13:07anible onto your local development
  358. 13:09machine so that you can develop your own
  359. 13:11anible Playbook coming back to the
  360. 13:13question like why an is called agentless
  361. 13:16to answer that question here I have
  362. 13:18prepared a diagram and onto the left
  363. 13:20hand side you will see a developer uh
  364. 13:22with his or her laptop or working laptop
  365. 13:25where he has or she has installed anible
  366. 13:29and on the right hand side you will see
  367. 13:30the remote servers uh it can be on
  368. 13:33premise remote server it can be uh
  369. 13:35hosted on a Google Cloud platform or AWS
  370. 13:38or any other cloud provider but that REM
  371. 13:41uh server has to be remote okay so now
  372. 13:44uh there is anible and that anible we
  373. 13:46have installed onto the developer
  374. 13:48machines not onto the servers so pay
  375. 13:52attention carefully we have installed
  376. 13:54anible on a developer machine so if I'm
  377. 13:56working on my playbook then I have
  378. 13:58installed nible on my local development
  379. 14:00machine so I will prepare my uh ncble
  380. 14:04Playbook I will write some instructions
  381. 14:06inside my ncble playbook and I I will
  382. 14:09run the ncble Playbook command and as
  383. 14:11soon as I run the ncble Playbook command
  384. 14:13it will connect to those servers using
  385. 14:16SSH it is same as when you try to log to
  386. 14:19your remote server using SSH so it will
  387. 14:21use the SSH it will connect to those
  388. 14:23server and it will execute all the
  389. 14:26required command which is necessary or
  390. 14:28which we have a speci classified into
  391. 14:30our playbooks so this is why the anible
  392. 14:33is called agentless all right so now we
  393. 14:35know that anible is agentless now the
  394. 14:38next question comes like how can I write
  395. 14:40the anible Playbook and what's the
  396. 14:42extension uh in which I should save the
  397. 14:45anible Playbook so as you can see onto
  398. 14:47the diagram onto the left hand side so
  399. 14:49you need to save your anible playbook
  400. 14:51with the extension. yml so yml extension
  401. 14:55is used for anible Playbook and you have
  402. 14:57to follow the yml conventions to write
  403. 15:00your anible instructions inside your
  404. 15:02anible playbook and here you can see I
  405. 15:04have taken a very basic uh code snippet
  406. 15:07screenshot where I have created uh like
  407. 15:10anible instruction for installing the
  408. 15:12Apache server so this file I'm just
  409. 15:14going to save with the yml extension and
  410. 15:16then I'm just going to execute the N
  411. 15:18Playbook command to uh run it on a
  412. 15:20different different server so this is
  413. 15:22the uh diagram which I just wanted to
  414. 15:24show you like how you're going to create
  415. 15:26and save your uh ncble Playbook with the
  416. 15:29yml extension now the next thing which
  417. 15:30you need to do you need to install the
  418. 15:32anible based on the operating system
  419. 15:34which you are using so first I will
  420. 15:37start with the windows and as you know
  421. 15:39from the Windows 10 and windows 11 we
  422. 15:41have the capability to run the Linux uh
  423. 15:43operating system inside your Windows
  424. 15:45machine so for that we will be using WSL
  425. 15:49uh utility provided by our Windows to
  426. 15:51install the ubun 2 or a Santos based
  427. 15:53operating system inside your Windows
  428. 15:56machine because uh it is really easy to
  429. 15:58run the anible in inside your Linux
  430. 16:01machine so for that purpose we are going
  431. 16:03to use the WSL utility for Windows here
  432. 16:06onto the screen you can see there is a
  433. 16:08really good documentation from a
  434. 16:09canonical entu community and this is the
  435. 16:12official page of the canonical entu
  436. 16:14where they have shown like how to set up
  437. 16:16your WSL on a Windows 10 as well as
  438. 16:19Windows 11 machines so here first of all
  439. 16:22you need to uh install the WSL utility
  440. 16:25so this particular section or these two
  441. 16:27links actually uh this is for Windows 10
  442. 16:31and this link is for Windows 10 as well
  443. 16:33as the windows 11 so I'll put both of
  444. 16:36the link into the description section of
  445. 16:38the video so if you are using the
  446. 16:39windows then I would highly recommend to
  447. 16:41follow these uh instruction which is
  448. 16:44mentioned on uban 2 canonical okay so
  449. 16:47let's go through it so this is the
  450. 16:48overview like uh what you need to do uh
  451. 16:51second if you click on the WSL then they
  452. 16:53have taken a really good screenshots
  453. 16:55like how to proceed forward so here uh
  454. 16:58you first go need to go to the Microsoft
  455. 17:00store where you need to look for a
  456. 17:01Windows subsystem and after that you
  457. 17:04need to install that thing and once you
  458. 17:07install the windows subsystem then you
  459. 17:09will get this terminal and there you
  460. 17:11need to install the Ubuntu so here after
  461. 17:14that you need to uh download the uban 2
  462. 17:17and here you need to mention like uh
  463. 17:19what version you need to install for the
  464. 17:21uban 2 I would recommend choose uh the
  465. 17:24long-term uh LTS based UB 2 version
  466. 17:27system because uh canonical has a really
  467. 17:30good support for LTS version so I would
  468. 17:32recommend to choose the latest and LTS
  469. 17:34version of Uub 2 so here you can
  470. 17:37download the uban 2 and once you have
  471. 17:39downloaded the uban 2 then you can uh go
  472. 17:41to this start screen select the uban 2
  473. 17:44and the maybe the next step would be the
  474. 17:46configure UB 2 and here you will see the
  475. 17:49terminal where you can just log to your
  476. 17:52UB 2 machine uh so that you just need to
  477. 17:54provide the username and the
  478. 17:56password and after that once you have
  479. 17:58installed the ubu then the First Command
  480. 18:00which you need to run is the Pudo appt
  481. 18:02update onto the terminal so that it can
  482. 18:05update its packages and at last you can
  483. 18:07install and use the GUI packages uh
  484. 18:10which is provided by a WSL for your ubu
  485. 18:13so that you can use the graphical
  486. 18:14interface uh for your UB 2 machine so
  487. 18:17just follow these instructions and uh uh
  488. 18:20set up your WSL uh based on the Windows
  489. 18:2310 or Windows 11 operating system and
  490. 18:26once you have a WSL and ubun 2 setup on
  491. 18:28your Windows machine then you can simply
  492. 18:31jump uh to the next instruction uh like
  493. 18:34uh the second and the third operating
  494. 18:36system like Ubuntu or Santo so here I'm
  495. 18:39assuming that on your Windows machine
  496. 18:41you are using Ubuntu so you can just
  497. 18:44follow the Pudo app to get install
  498. 18:46anible command which I'll I'll show you
  499. 18:48onto my one to machine uh that how to
  500. 18:51install the anible so you can just
  501. 18:52simply follow those instructions to
  502. 18:54install uh anible because on Windows
  503. 18:57machine you are running to then you just
  504. 18:59need to copy these instructions over
  505. 19:01there and you can uh just get yourself
  506. 19:04started with the so here is my terminal
  507. 19:06and this is my Ubuntu machine so first
  508. 19:08of all let's verify the version of my
  509. 19:10Ubuntu Machine by running this command
  510. 19:12so here you can see this is the Debian
  511. 19:14based uh operating system so deian based
  512. 19:16also like Ubuntu is a Debian based
  513. 19:18operating system so all the command
  514. 19:21which I'm running over here will be uh
  515. 19:23applicable for any Ubuntu machine so if
  516. 19:26you are using Ubuntu on your Windows
  517. 19:27machine then you can simply run these
  518. 19:29commands to install the nle so the First
  519. 19:32Command which I'm just going to run I'll
  520. 19:34first of all clear the screen is Pudo
  521. 19:36app gate update so this is the first
  522. 19:38command I would recommend you to run so
  523. 19:40that it can update all the uh apt
  524. 19:42packages all right so that has been done
  525. 19:45successfully the next command which I'm
  526. 19:47just going to run is to in install the
  527. 19:49anible uh repository but before that I'm
  528. 19:52just going to run this uh install
  529. 19:54software properties common command type
  530. 19:58yes it will install it okay that's been
  531. 20:00done I'll clear the screen now I'm just
  532. 20:02going to install the repository from
  533. 20:04where we are just going to fetch the an
  534. 20:06so this is the command for installing or
  535. 20:09installing the anible repository onto my
  536. 20:11Ubuntu machine so I'm just going to
  537. 20:13Simply hit enter and just going to press
  538. 20:15enter and here we have downloaded the
  539. 20:17repository for anible and the next
  540. 20:19command which I'm just going to run is
  541. 20:21the Pudo epate update once again because
  542. 20:24we have just recently added the uh
  543. 20:26anible repository so this is the command
  544. 20:28to update the uh repository definitions
  545. 20:31over here and here we can see our anible
  546. 20:35repository has been
  547. 20:37updated okay I'll clear the screen and
  548. 20:40the final command which I'm just going
  549. 20:41to run is the Pudo apate update install
  550. 20:45anible and hit enter type yes all right
  551. 20:49so here you can see our anible
  552. 20:51installation has been finished so I'm
  553. 20:52just going to clear the screen and I'm
  554. 20:54just going to run the
  555. 20:55anible version command to verify by the
  556. 21:00version uh I would say I'll C the screen
  557. 21:02once more I need to add one more Dash
  558. 21:05over here to get the correct version and
  559. 21:08here you can see this is the version uh
  560. 21:10Nal 2.10 which we have installed onto
  561. 21:12our2 machine I'll put all this command
  562. 21:15into the description section uh so that
  563. 21:17you can follow this command to install
  564. 21:19the uh anible onto your ub2 system the
  565. 21:23next uh we are going to do we are just
  566. 21:25going to install the anible onto the
  567. 21:27sent OS the Y uh package manager okay so
  568. 21:30the next uh installation which we are
  569. 21:32going to do we are just going to install
  570. 21:34onto our Santo operating system so we
  571. 21:36have covered the windows we have covered
  572. 21:38the UB to the next thing which we are
  573. 21:39going to do we are going to install the
  574. 21:41anible onto the sent OS so this is the
  575. 21:44terminal of my Centos machine I'm just
  576. 21:46going to minimize this thing so this is
  577. 21:48the terminal from my sent OS machine so
  578. 21:51first of all let's verify the santoos
  579. 21:53version and the command for that is cat
  580. 21:55Etc santoos release and it will let you
  581. 21:58know the version so here I'm using the
  582. 21:59Santos release 8 version so that we have
  583. 22:03verified the next thing which we are
  584. 22:04going to do we are just going to run the
  585. 22:06Yum update command so that uh uh we
  586. 22:09update all the package manager so the
  587. 22:12command is sudo uh yum
  588. 22:15update okay so now we have finished the
  589. 22:17Yum update command so I'm just going to
  590. 22:19clear the screen the next command which
  591. 22:20I'm just going to run is the Pudo uh
  592. 22:22sorry yum install eepl release and I'm
  593. 22:25just going to add Pudo over here
  594. 22:29so this will basically install the EPL
  595. 22:32release package and after that we will
  596. 22:34be able to install the anible onto our
  597. 22:36Santo
  598. 22:37machine type
  599. 22:39yes and here we have uh successfully
  600. 22:42installed the EPL release package and
  601. 22:44the next command which I'm just going to
  602. 22:46run is the I'm just going to clear the
  603. 22:48screen first of all sud sudo yum install
  604. 22:52anible all right so now the anible uh y
  605. 22:54install anible command has just finished
  606. 22:56I'm just going to clear the screen and
  607. 22:58I'm just going to verify the anible
  608. 23:00installation by running the command
  609. 23:02anible version and here you can see uh
  610. 23:05we have installed the anible 2.3.5 onto
  611. 23:08our Santo system the next thing which we
  612. 23:11are going to try out is we are just
  613. 23:12going to install uh anible onto our Mac
  614. 23:15OS if you are using the Mac OS then
  615. 23:18installation of a anible on a Mac OS is
  616. 23:21pretty simple uh you just need to rely
  617. 23:23on the Brew package manager and the
  618. 23:25command for installing the anible is the
  619. 23:27Brew install anel and that should take
  620. 23:30care of the anible installation onto
  621. 23:32your Mac OS so here you can see I have
  622. 23:35already installed anible that's why it
  623. 23:37is showing me that anel has already
  624. 23:39installed but in case if you don't have
  625. 23:41anel installed onto your Mac operating
  626. 23:43system then you just simply need to
  627. 23:45execute PR install anible and that will
  628. 23:47take care of the anible installation now
  629. 23:50after installing the anible the next lap
  630. 23:52session we are going to discuss more
  631. 23:54about the anible project setup so here I
  632. 23:56have taken a very brief screenshot where
  633. 23:59I have shown a project structure of my
  634. 24:01anible project so where I have shown
  635. 24:03like how I have created the inventory
  636. 24:05file uh where is my host file what are
  637. 24:07the roles I need to create inside my
  638. 24:09anible playbook uh what does it mean by
  639. 24:12the task uh and how should I set up my
  640. 24:14anible uh Playbook yml so this is the
  641. 24:17project setup we will take a deep dive
  642. 24:19into for our next
  643. 24:23session welcome back and till now so far
  644. 24:26we have seen like what the is and how to
  645. 24:29do the Nel installation but in this lab
  646. 24:32session we are going to take a look onto
  647. 24:33the project structure of our Nel so here
  648. 24:36we will talk about the inventory file we
  649. 24:38will talk about the task and our main
  650. 24:40Playbook and how to execute it so here
  651. 24:43you can see onto the screen this is the
  652. 24:45typical project structure of my anible
  653. 24:47so here we are talking about the
  654. 24:49inventory roles and my main Playbook
  655. 24:51file but don't worry we are going to
  656. 24:53take a look onto the each uh file which
  657. 24:56is present inside our project structure
  658. 24:58moving to the next slide so here you
  659. 24:59will see a remote server with a
  660. 25:01dedicated IP so I'm just assuming that
  661. 25:04this is going to be my dedicated server
  662. 25:06and for This Server I'm just going to
  663. 25:08write my anible playbook so first of all
  664. 25:12in this slide you will see on the right
  665. 25:13hand side my dedicated server which is a
  666. 25:16remote server present somewhere and
  667. 25:18after that you will on the left hand
  668. 25:19side you will see this is the typical
  669. 25:21project structure of my anel so we'll
  670. 25:24start from the host file so if you'll
  671. 25:26see uh whenever you work with anible
  672. 25:28then you need to create the host file
  673. 25:30and inside that host file you need to
  674. 25:32mention the either IP address or the
  675. 25:35domain name of our particular remote
  676. 25:37machine so here you can see this is the
  677. 25:39uh IP address which I have written it
  678. 25:41over here inside my host file so that
  679. 25:44anible knows like which host it can
  680. 25:47connect so here this is a single server
  681. 25:49I have used inside my anible playbook so
  682. 25:52that's why I'm using the single IP over
  683. 25:54here but in case if you are having a
  684. 25:56multiple server then you can create a
  685. 25:57multi mle entries inside this host file
  686. 26:01so this is how it works so here you will
  687. 26:03have a host file in your project inside
  688. 26:06the inventory directory and inside that
  689. 26:08inventory directory you can create a
  690. 26:09multiple host file also that's
  691. 26:12absolutely okay so I'm just taking one
  692. 26:14example uh for Server remote server so
  693. 26:16that's why I have only one host file and
  694. 26:19this host file contains the IP address
  695. 26:21and this IP address will point to our
  696. 26:23remote machine so that's the first uh
  697. 26:26basic file which we need for creating
  698. 26:29our anible Playbook and that is our host
  699. 26:31file all right moving to the next file
  700. 26:33where we will be talking about the roles
  701. 26:35and the task associated with particular
  702. 26:37role so here onto the screen if you'll
  703. 26:40see this is the main. yml which is a
  704. 26:42task present inside a role and the role
  705. 26:45name is python so pay attention
  706. 26:47carefully over here for anible Playbook
  707. 26:50you can have a multiple role and each
  708. 26:52role can have a task so here I have
  709. 26:55created a role that is Python and inside
  710. 26:57that pyth python we have a task and that
  711. 27:00task we have defined inside our main.
  712. 27:02yml and what's the purpose of that
  713. 27:05particular task so in this task we we
  714. 27:08are trying to execute uh the python
  715. 27:11installation and after that we are just
  716. 27:12trying to create a directory and then
  717. 27:15after that we just trying to install the
  718. 27:16Apache so this task basically contains
  719. 27:19the three uh instruction which we need
  720. 27:22to uh perform onto our remote machine
  721. 27:24using anel so once we execute this
  722. 27:27anible plate book then this particular
  723. 27:30task that is python task will be
  724. 27:32executed and once it is executed then
  725. 27:34these three instructions will be pass to
  726. 27:36the server using our anel so that's the
  727. 27:39purpose of our roles and the task inside
  728. 27:42our anel all right so now the final
  729. 27:44piece inside our anible project is our
  730. 27:47anible Playbook so if you look onto the
  731. 27:49screen so this is the name of my
  732. 27:51playbook so the Playbook name is VM
  733. 27:53setup playay book. yml you can keep any
  734. 27:56name of your choice for your anible
  735. 27:58Playbook that's absolutely okay now
  736. 28:01since we have talked about uh task as
  737. 28:03well as our host file so we need to
  738. 28:05include both the host as well as the
  739. 28:08task inside our anible Playbook so if
  740. 28:10you'll see over here so this is my uh VM
  741. 28:13setup Playbook yml that is a my playbook
  742. 28:16for anible and in this file you will see
  743. 28:19two thing so at the line number three
  744. 28:21you will find host that means what host
  745. 28:24it is going to connect so here I have
  746. 28:26specified all so that means it is going
  747. 28:28to execute this Playbook on all the host
  748. 28:31which I have defined inside my host file
  749. 28:34so here in my host file I only defined
  750. 28:36one remote server so this Playbook will
  751. 28:39run on that particular remote machine so
  752. 28:42if you have more than one host inside my
  753. 28:45host file then this Playbook will run on
  754. 28:47all those host machine so that's why the
  755. 28:49host all we have defined over here the
  756. 28:52next thing we need to Define is the
  757. 28:54remote user so whenever you try to
  758. 28:56connect to any remote machine using SSH
  759. 28:59then you need to have a username so here
  760. 29:01we need to define the username what will
  761. 29:03be the remote user so here I'm using
  762. 29:05Ubuntu as my remote user for that
  763. 29:08particular machine and this might differ
  764. 29:10because if you're working on anible
  765. 29:12Project then you might have uh remote
  766. 29:15server access with your own username so
  767. 29:17you need to use your own username
  768. 29:19instead of Ubuntu over here so that's
  769. 29:21the purpose of the remote user the third
  770. 29:24thing which you will see over here into
  771. 29:26this Playbook is the roles so here here
  772. 29:28uh the the second uh picture if you'll
  773. 29:30see over here so where we have defined
  774. 29:32the main. yml and where we have defined
  775. 29:34the different different tasks so this is
  776. 29:37the role which we need to include and
  777. 29:38that is Python and if you that python
  778. 29:41role is available inside our project
  779. 29:43screenshot where you can see roles
  780. 29:45Python and task so here we have included
  781. 29:48the python role so this is how this
  782. 29:50complete anible works and how you put
  783. 29:53host as well as your roles and task as
  784. 29:56well as uh your own user if you're are
  785. 29:59having your own user assigned to that
  786. 30:01remote machine so you need to put the
  787. 30:03usern name onto your anible playb all
  788. 30:06right so now you know like how the N
  789. 30:08project looks like and what is your host
  790. 30:10inventory roles and task now what's the
  791. 30:13command for executing this whole project
  792. 30:15so here onto the screen you will see the
  793. 30:17anible Playbook command which I have
  794. 30:19mentioned for this particular project
  795. 30:21and this anible uh Playbook command I
  796. 30:24have break I have broke into three parts
  797. 30:26so first part is the anible Playbook
  798. 30:28that's the actual keyword which we need
  799. 30:30to use after installing the N second we
  800. 30:33need to specify like which host on which
  801. 30:36we want to run so here we have a
  802. 30:38specified inventory and then inside that
  803. 30:40inventory we need to specify the exact
  804. 30:43path of our host file so that host file
  805. 30:45is present under inventory VM setup
  806. 30:48Playbook and host that's the name of my
  807. 30:50host file so you need to carefully
  808. 30:53assign the host name or the host path
  809. 30:55over here the third thing is is the
  810. 30:58actual Playbook name so that's my actual
  811. 31:00Playbook which I have created which
  812. 31:02consist of roles uh remote user and the
  813. 31:05host file on which host we want to
  814. 31:08execute actually so this is the anible
  815. 31:10Playbook command which you need to run
  816. 31:13to execute this whole project all right
  817. 31:16so now you have a little bit of fair
  818. 31:18understanding on the anible project
  819. 31:19structure now we will take a deep dive
  820. 31:22into the each individual file which I
  821. 31:24have just explained to you so here onto
  822. 31:26the screen the first file which are
  823. 31:28which we are going to see over here is
  824. 31:30the VM setup Playbook yml so here first
  825. 31:33of all we need to specify the name of
  826. 31:35the Playbook uh that's something a
  827. 31:37description which you can put second
  828. 31:39here we need to specify the host so that
  829. 31:42I have specified as all so let's take a
  830. 31:45look onto the host file first of all so
  831. 31:47here onto this project you will find a
  832. 31:50host file which I have created and
  833. 31:52inside that host file I have created a
  834. 31:54suitable name like gcp host because that
  835. 31:56virtual machine is on to Google Cloud
  836. 31:59but that's something I will explain it
  837. 32:01later like how to set up the Google
  838. 32:03cloud or AWS but that's something for
  839. 32:06later sessions but here uh I have
  840. 32:09specified the IP address and uh this is
  841. 32:11the uh private key which I will be using
  842. 32:14to connect to that particular machine
  843. 32:16but I have a next chapter for this SSH
  844. 32:18private key and public key setup with
  845. 32:20the anible but the key thing over here
  846. 32:23is this particular IP address so that's
  847. 32:26the remote machine IP address which I
  848. 32:28will be needing or this anible Playbook
  849. 32:30will be needing so that's why uh this uh
  850. 32:33uh this Playbook contains the host all
  851. 32:35so that means all the host inside this
  852. 32:38particular uh this particular host file
  853. 32:40so here I have only one if in case I
  854. 32:42have more than uh one or two then I can
  855. 32:45execute the Playbook on all those host
  856. 32:48that's the purpose of that all inside
  857. 32:50that particular and civil Playbook okay
  858. 32:52moving back to the Playbook once again
  859. 32:54so now we have seen the name we have
  860. 32:56seen the host now we need to look onto
  861. 32:59the remote user so as you remember
  862. 33:02whenever you connect to the remote
  863. 33:04machine then you need to have a remote
  864. 33:06user so here the remote user is rul p so
  865. 33:10that's the user which exist onto that
  866. 33:12remote machine I'll I'll show you all
  867. 33:15right so this is my terminal and I'm
  868. 33:16just going to SSH into this machine
  869. 33:18using the username Rahul V so I'm just
  870. 33:21going to paste the command over here so
  871. 33:23if you'll see this is the SSH and this
  872. 33:25is my host uh this is my priv private
  873. 33:28SSH key and this is the username and the
  874. 33:31IP address of my machine and in case if
  875. 33:33you're are not using the private key
  876. 33:35then you can simply use the username and
  877. 33:37the password assigned to you so here I'm
  878. 33:40just using private uh and the public key
  879. 33:42that's why I don't need to assign my
  880. 33:44username and password but this just an
  881. 33:47example uh if you have a username and
  882. 33:49password then it's absolutely okay to
  883. 33:51SSH using the username and password and
  884. 33:53you can just simply enter type yes to
  885. 33:56accept it and here you can see uh I just
  886. 33:59logged in into my machine and the
  887. 34:01username is Rahul V because that's the
  888. 34:04user I have created on that Linux
  889. 34:06machine so I just wanted to show you
  890. 34:08because uh if you go to this ncble
  891. 34:11Playbook once again so that's why I have
  892. 34:13used the remote user over here as Rahul
  893. 34:16V so you need to know like what kind of
  894. 34:18a user you want to become over there and
  895. 34:21if you want to execute with the root
  896. 34:22then you can mention the root also over
  897. 34:25here that's absolutely fine with the
  898. 34:26anible now the last last thing which is
  899. 34:28left inside this Playbook is the roles
  900. 34:30and roles I'm using over here is python
  901. 34:33so here you if you take a look onto this
  902. 34:35rules directory I'll just close it and I
  903. 34:37reopen it so here we are having a roles
  904. 34:39and inside that role we have defined the
  905. 34:41role as Python and in that inside that
  906. 34:44python Ro we have a task and that task
  907. 34:46contains main. yml so if you open that
  908. 34:49main. yml then you will find the uh
  909. 34:51instruction which we need to execute
  910. 34:53onto that remote machine so here I'm
  911. 34:55installing Python and I'm just creating
  912. 34:58One Directory over here and then I'm
  913. 35:00finally I'm installing the apach so
  914. 35:03that's the task definition or the test
  915. 35:05task configuration of our anible looks
  916. 35:08like so these instructions going to
  917. 35:09execute onto our anible Playbook now the
  918. 35:12next thing which I'm just going to do
  919. 35:13I'm just going to Simply run the
  920. 35:15Playbook and see if that works or not
  921. 35:17all right so now I have opened the
  922. 35:19terminal once again and I'm just going
  923. 35:20to execute the anible Playbook command
  924. 35:22so this is my anible playbook command
  925. 35:24and I'm just going to Simply hit enter
  926. 35:26uh type yes for accepting it and since
  927. 35:30I'm using the private key so I don't
  928. 35:31need to input my username and password
  929. 35:34and in case if you're not using the uh
  930. 35:37public and private key then you need to
  931. 35:39enter the username and password so that
  932. 35:41anible Playbook can run so that's the
  933. 35:43difference between this setup and the
  934. 35:44username password setup and this ncble
  935. 35:47Playbook might take a couple of minute
  936. 35:49to execute it so I'll just fast forward
  937. 35:52this uh session and I'll come back when
  938. 35:54this Playbook has executed successfully
  939. 35:57all right so here here you can see our
  940. 35:58ncble Playbook had just finished and you
  941. 36:00can see the status over here three Chang
  942. 36:03that means it has installed python it
  943. 36:05has created a directory and it has also
  944. 36:07installed the aach to that's why the
  945. 36:09count as three and just in case if
  946. 36:11Playbook fails and if there is there are
  947. 36:13any error then those errors will be
  948. 36:15visible over here in the red color font
  949. 36:17but here our ncble Playbook has
  950. 36:19successfully finished so I'm just going
  951. 36:21to clear the screen over here and we are
  952. 36:23just going to verify uh by logging into
  953. 36:26the server or just as s into the server
  954. 36:28so this is the command for SSH into the
  955. 36:30server I'm just going to hit enter and
  956. 36:32here you can see I'm just logged in and
  957. 36:34I'm just going to run the First Command
  958. 36:35that is python uh 3 version and here you
  959. 36:40can see python has been installed so our
  960. 36:41first task has been completed
  961. 36:43successfully the next command which I'm
  962. 36:44just going to run is the ls command and
  963. 36:46here you can see the directory basic
  964. 36:48HTTP server has been created so that
  965. 36:50directory I just wanted to create and
  966. 36:53the final thing which I need to verify
  967. 36:54is the I'll just clear the screen over
  968. 36:56here uh the system
  969. 36:59CTL uh
  970. 37:02status Apache 2 and here you can see the
  971. 37:07Apache 2 service is green that means our
  972. 37:09Apache 2 has been installed using anle
  973. 37:13so that's the verification part of our
  974. 37:15anible Playbook uh which we have just
  975. 37:17executed so now with that we have
  976. 37:19finished our chapter where we have seen
  977. 37:21like how to set up your anible project
  978. 37:23and how to execute your anible playbook
  979. 37:26now into the next chapter we will take a
  980. 37:28look onto the public and private key how
  981. 37:30to create your public and private key
  982. 37:32and how to associate those public and
  983. 37:34private key with your anible
  984. 37:37playbook all right so in this chapter we
  985. 37:39are going to talk about the SSH keys and
  986. 37:41the anible Playbook so whenever we talk
  987. 37:44about the SSH Keys then we are talking
  988. 37:46about the two keys one is the public key
  989. 37:48and one is the private key and since we
  990. 37:50are working with the an so the private
  991. 37:52key part will always remain with our
  992. 37:55anible Playbook which is local to you
  993. 37:58and the public key will always go onto
  994. 38:00the remote server so first of all we are
  995. 38:03just going to create those keys and then
  996. 38:04we are going to use the private key for
  997. 38:06our host inside our host file and the
  998. 38:09public key uh which we are going to copy
  999. 38:11it to our remote server let's switch
  1000. 38:13over to our desktop and see the demo so
  1001. 38:16here onto the screen you can see uh on
  1002. 38:18the left hand side this is my anible
  1003. 38:20playbook where my private key is and
  1004. 38:22then we are going to execute the anible
  1005. 38:24Playbook and then it is going to
  1006. 38:26communicate with our remote server with
  1007. 38:28a dedicated IP this IP is just an
  1008. 38:30example and in this uh remote server we
  1009. 38:33will have our public key but the
  1010. 38:35question comes like how you are going to
  1011. 38:36generate the SSH key so on the screen
  1012. 38:39you will see on the left hand side this
  1013. 38:41is the command which we are going to use
  1014. 38:42to create our SSH keys so here we will
  1015. 38:45be creating two keys so on the right
  1016. 38:47hand side you will see anible demo and
  1017. 38:49anbl demo. Pub so uh anible demo under _
  1018. 38:54demo is going to be our private key and
  1019. 38:56anore demo. Pub will be our public key
  1020. 39:00so these two keys we will be creating
  1021. 39:03and the public key we will try to copy
  1022. 39:05it to our remote server so I'll switch
  1023. 39:08over to my terminal and first of all
  1024. 39:09let's create the SSH keys so here is my
  1025. 39:12terminal and the command which I'm just
  1026. 39:14going to run is the
  1027. 39:15SSH keys
  1028. 39:18in and here it will ask for the name of
  1029. 39:20the keys which you want to create so I'm
  1030. 39:22just going to use the same location I
  1031. 39:25just wanted to create the uh keys on to
  1032. 39:27the same location and the name of the
  1033. 39:29key is
  1034. 39:31anible uncore
  1035. 39:33demo but you can specify your own path
  1036. 39:36where you want to create those SSH keys
  1037. 39:38I'm just creating it over here that that
  1038. 39:40just for an example and simply hit enter
  1039. 39:44I don't want to associate any pass
  1040. 39:46phrase so I'm just going to keep it
  1041. 39:47empty again empty and that's how we are
  1042. 39:50just going to create the SSH keys so
  1043. 39:52here you will see this is our first key
  1044. 39:55uh that is ncore demo that is is our
  1045. 39:57private key and this is going to be the
  1046. 39:59second key which is our public key uh
  1047. 40:02that is also present under SSH and it is
  1048. 40:06ending with the extension. pub that
  1049. 40:08means that is our public key now let's
  1050. 40:10take a look onto the previous slide
  1051. 40:12which I have shown so here uh we have
  1052. 40:13created the anible demo that is our
  1053. 40:15private key as well as the public key
  1054. 40:18the next thing which we need to do is we
  1055. 40:19need to copy the public key to our
  1056. 40:21remote server that means we need to copy
  1057. 40:23_ demo. pup key to our remote server
  1058. 40:27server so I'm just going to use the SSH
  1059. 40:29copy command to copy this public key to
  1060. 40:31our remote server so this is my terminal
  1061. 40:33and the command which I'm just going to
  1062. 40:35use is SSH copy ID if I can could show
  1063. 40:38you over here so this is the SSH copy ID
  1064. 40:41command after that I need to use the I
  1065. 40:43flag and here I need to specify the
  1066. 40:45public key which is present onto my
  1067. 40:47system so this is the public key which
  1068. 40:49is present and after that I need to
  1069. 40:50specify the username account which is
  1070. 40:53present onto that remote server and the
  1071. 40:55IP address of that particular remote
  1072. 40:57server so once it is done then you just
  1073. 41:00simply need to hit enter and it will ask
  1074. 41:03for the password of our remote server so
  1075. 41:06again I'm just going to copy the
  1076. 41:07password from my notepad and paste it
  1077. 41:09over
  1078. 41:10here and here you can see the one key
  1079. 41:13has been added so that means we have
  1080. 41:14successfully added our public key to the
  1081. 41:17remote server now coming back to the
  1082. 41:20presentation once
  1083. 41:21again so our the part of copying the
  1084. 41:24public key to the remote server is over
  1085. 41:26now we need to associate our private key
  1086. 41:29with our anible Playbook okay so here's
  1087. 41:32my anible playbook uh this is my anible
  1088. 41:34playbook and where we need to associate
  1089. 41:37our private key part so you need to go
  1090. 41:39to the host file this is the IP address
  1091. 41:42of my uh remote machine and this is the
  1092. 41:46path actually this is the path of my
  1093. 41:48private key so here this is the keyword
  1094. 41:50anible SSH private key file that's the
  1095. 41:53keyword from anible and here you need to
  1096. 41:55specify the path of your private key so
  1097. 41:58here I'm just going to use my new key
  1098. 42:00that is analore demo that's going to be
  1099. 42:03the my private key for this anible
  1100. 42:05Playbook so I'm just going to open the
  1101. 42:07terminal once again and I'm just going
  1102. 42:08to rerun The anible Playbook with my new
  1103. 42:12private key so here the Playbook command
  1104. 42:14is again pretty simple anible Playbook
  1105. 42:16then the inventory file where my host
  1106. 42:18and the private key definition exist and
  1107. 42:20the name of my playbook and I'm just
  1108. 42:21simply going to hit enter and now this
  1109. 42:24time it is going to use my newly created
  1110. 42:26private key uh from my local machine to
  1111. 42:28connect to our remote server so here you
  1112. 42:31can see our uh command has successfully
  1113. 42:33completed and this time I have reduced
  1114. 42:35the Playbook so over here if you'll see
  1115. 42:38so I'm just creating a very basic
  1116. 42:40directory just to verify that I'm able
  1117. 42:42to connect to remote server and I'm able
  1118. 42:44to create a uh directory into my remote
  1119. 42:47machine Let's SSH into the OR login into
  1120. 42:50the server and verify that our directory
  1121. 42:52has been created or not so I'm just
  1122. 42:54going to use this command to SSH into my
  1123. 42:56system
  1124. 42:58and here we are able to log in into our
  1125. 43:01remote server and I'm just going to run
  1126. 43:02the ls command and here you can see our
  1127. 43:04directory has been created with the name
  1128. 43:06basic HTTP server all right so now you
  1129. 43:08have seen like how to create the public
  1130. 43:10key and the private key and how to use
  1131. 43:12those keys to SSH into your remote
  1132. 43:15server while you're running the anible
  1133. 43:17Playbook but now into the next session
  1134. 43:19we'll take a look on one of the most
  1135. 43:21basic concept that is yml which is used
  1136. 43:24for writing the anible Playbook so we'll
  1137. 43:26take a look onto the example yml which I
  1138. 43:29have used in previous session so that is
  1139. 43:31going to be one of the basic yml and we
  1140. 43:33will focus on the concept like what are
  1141. 43:35the indentation rule what are the syntax
  1142. 43:38you need to follow while writing your
  1143. 43:39own anible Playbook so that is going to
  1144. 43:42be the next session for our anible
  1145. 43:46series all right so let's talk about the
  1146. 43:48yml and why should we use yml for
  1147. 43:51writing your own anible Playbook
  1148. 43:53obviously the first question comes in my
  1149. 43:55mind that what is yml and what it stands
  1150. 43:58for so the full form of yml is yml and a
  1151. 44:01markup language as the name suggests yml
  1152. 44:04isn't a markup language so that means
  1153. 44:06you don't need to use those traditional
  1154. 44:08Syntax for writing your ymls so if there
  1155. 44:11are no any markup syntax which you need
  1156. 44:13to use for writing your own yml then
  1157. 44:15what kind of a rules you should use for
  1158. 44:17writing your yml so whenever you try to
  1159. 44:20write a yml whether it's for your anible
  1160. 44:23Playbook or if you're trying to Define
  1161. 44:25any configuration so whenever you write
  1162. 44:27yml then you need to carefully look on
  1163. 44:30the indentations now you might be
  1164. 44:32wondering like what is indentation so
  1165. 44:34you might be familiar with the concept
  1166. 44:36of indentation in some other programming
  1167. 44:38languages but when we talk about the
  1168. 44:40ymls then you need to follow that
  1169. 44:42indentation rule very carefully so here
  1170. 44:45onto the screen you can see the example
  1171. 44:47of indentation which I took so here you
  1172. 44:49will see item one and item two that that
  1173. 44:51are starting on a certain horizontal
  1174. 44:54position but sub item one and sub item
  1175. 44:56two is is starting on a different
  1176. 44:58horizontal position from item one and
  1177. 45:00item two so these different horizontal
  1178. 45:03position for each line item is called as
  1179. 45:06indentation but you need to be really
  1180. 45:08careful on defining the parent item and
  1181. 45:10the child item so here the parent item
  1182. 45:13I'm talking about is the item two is the
  1183. 45:15parent and the sub item one and sub item
  1184. 45:17two is the child so parent item will
  1185. 45:20have a different horizontal position but
  1186. 45:23sub item will have a different
  1187. 45:24horizontal position so these horizontal
  1188. 45:27Position will Define like which is
  1189. 45:28parent and which is child and using this
  1190. 45:31concept we are going to write our anible
  1191. 45:33Playbook where we will be writing the
  1192. 45:35parent item with the task and the
  1193. 45:37description and then also we are going
  1194. 45:39to write the child item inside our
  1195. 45:41Playbook let's take an example where I
  1196. 45:43have written a very basic yml for my
  1197. 45:46anible so whenever you write a yml then
  1198. 45:49you should start your first line with
  1199. 45:51the three dashes so here you can see
  1200. 45:52onto the screen my first line start with
  1201. 45:55the three dashes moving to the next line
  1202. 45:57and there where it comes the name so the
  1203. 46:00name attribute defines like what your
  1204. 46:02task does so here you can put a
  1205. 46:05meaningful sentence like which describe
  1206. 46:07what kind of a task you're trying to do
  1207. 46:09so here I'm just trying to create a
  1208. 46:11directory that's why I have put a
  1209. 46:12description over here that is Meaningful
  1210. 46:15that particular task but the second line
  1211. 46:18always starts with a single Dash so it
  1212. 46:21is always like single Dash and then name
  1213. 46:23and then your description of that
  1214. 46:25particular task now moving to the third
  1215. 46:28line and the third line is depend upon
  1216. 46:31like what kind of an anible Playbook you
  1217. 46:33are writing so here I'm just trying to
  1218. 46:35create a directory so here I need to use
  1219. 46:38the module name so the module which uh I
  1220. 46:41need to use for this Playbook is the
  1221. 46:43file so that's why my third line I'm
  1222. 46:45using the keyword that is file and that
  1223. 46:48file module is responsible for creating
  1224. 46:50or deleting the directory whenever I'm
  1225. 46:53working with the anle so that's why the
  1226. 46:56file name comes from and if you look
  1227. 46:58carefully the line number third that
  1228. 47:00starting at a certain horizontal
  1229. 47:02position and that horizontal position is
  1230. 47:04defined by a single tab all right so now
  1231. 47:07we have defined the parent attribute as
  1232. 47:09file the next to line where we are going
  1233. 47:11to define the child attribute so
  1234. 47:14whenever you're working with the file
  1235. 47:15module of a anible then you need to
  1236. 47:17define the two more attribute that is
  1237. 47:20path and the state and if you look
  1238. 47:22carefully over here the indentation of a
  1239. 47:25path and the state attribute is little
  1240. 47:28bit more than the parent attribute of
  1241. 47:30file so here you will see I have put two
  1242. 47:33tabs for defining path as well as two
  1243. 47:36tabs for defining the state and with
  1244. 47:38these two additional tabs or the
  1245. 47:40indentation of a horizontal space you
  1246. 47:43tell yml that these are going to be my
  1247. 47:45child attribute so here path and the
  1248. 47:48state are going to be the child for a
  1249. 47:50file module and what's the purpose of a
  1250. 47:52path and a state attribute so whenever
  1251. 47:55you work with the file module and if if
  1252. 47:56you're trying to create a directory then
  1253. 47:58you need to specify the path like where
  1254. 48:01you need to create your directory so
  1255. 48:03then path attribute you're are just
  1256. 48:05going to define the path where our
  1257. 48:07directory will be created and the state
  1258. 48:09attribute is going to Define that it
  1259. 48:11will be created or it will be deleted
  1260. 48:14okay so this is the simplest example
  1261. 48:16which I have taken to explain how to
  1262. 48:18write the yml for your anible playbook
  1263. 48:21but considering the same example you can
  1264. 48:24write your own anible Playbook where you
  1265. 48:26can can have multiple tasks so this is
  1266. 48:28just a one task where I'm creating a
  1267. 48:30directory but you can have a n number of
  1268. 48:33a task inside your playbook but the
  1269. 48:35rules are same you just need to repeat
  1270. 48:37this process and follow the same
  1271. 48:40indentation rules for writing your next
  1272. 48:42task for your anible playbook I hope the
  1273. 48:45yml part is clear to you the next file
  1274. 48:47which I'm talking about is the host file
  1275. 48:50so in the host file where you trying to
  1276. 48:52define the host where you want to
  1277. 48:55execute your anible play the host file
  1278. 48:57can exist with the name hosts or it can
  1279. 49:00exist with the name hosts. inii and you
  1280. 49:03can write the host file uh with yml and
  1281. 49:06without yml also so the first example
  1282. 49:09which you can see over here where I have
  1283. 49:11written the host file without any yml
  1284. 49:13rules so here I'm just trying to define
  1285. 49:16the name of my host so here I have just
  1286. 49:18taken an example gcp host and after that
  1287. 49:22in the next line I have written the IP
  1288. 49:24address of my remote machine so that's
  1289. 49:26the simplest way of writing the host
  1290. 49:29file without using yml syntax but the
  1291. 49:31next example which I'm showing to you is
  1292. 49:33little bit more complex and here I have
  1293. 49:36taken the same example which I have
  1294. 49:38written without yml as well as with yml
  1295. 49:41so in the host file you can follow both
  1296. 49:43the uh rules like with the yml and
  1297. 49:45without yml and you can construct the
  1298. 49:48parent and the child relationship
  1299. 49:50between the different hosts so this is
  1300. 49:52the way you can create your own host
  1301. 49:55file so it just depends upon you like
  1302. 49:57which kind of a snex you want to prefer
  1303. 49:59but always remember try to put a
  1304. 50:01meaningful name on the each host so that
  1305. 50:04you can identify and you can pass the
  1306. 50:06correct host while running your anible
  1307. 50:08playbook so this is the host file which
  1308. 50:11you can write either in vml or without
  1309. 50:13using yml syntax I hope this session
  1310. 50:16will help you to understand anible in a
  1311. 50:18more better way and you can write your
  1312. 50:20own anible playbooks with multiple task
  1313. 50:23and the host file in the next session of
  1314. 50:25this anible series we we will be talking
  1315. 50:27about the handlers environment variables
  1316. 50:30variables and if then else statement so
  1317. 50:33stay tuned for that and if you haven't
  1318. 50:35followed the anible series then there
  1319. 50:36are some previous lab session on anible
  1320. 50:39which you can go and check so see you
  1321. 50:41into the next session till then take
  1322. 50:42care and
  1323. 50:44bye-bye hello there this is Rahul and
  1324. 50:47today let's talk about the anible
  1325. 50:49handlers before we jump into the anible
  1326. 50:51handlers demo it's really important to
  1327. 50:53understand what the an handlers are and
  1328. 50:56when should we use the anible handlers
  1329. 50:58inside your anible playbook let's take a
  1330. 51:00very hypothetical scenario that you are
  1331. 51:02having a website and you need to update
  1332. 51:05the content onto your website you have a
  1333. 51:07anible Playbook what it does it just
  1334. 51:10copies the updated HTML file onto the
  1335. 51:12server so that you can update the
  1336. 51:14content of your website but there is one
  1337. 51:16strict requirement that when you update
  1338. 51:19the content or when you update the HTML
  1339. 51:21file onto your application server then
  1340. 51:23you need to restart the whole
  1341. 51:25application server so that the updated
  1342. 51:27content can reflect onto your website so
  1343. 51:29how would you automate the whole process
  1344. 51:31so the first task in this process is
  1345. 51:33copy the updated HTML content onto your
  1346. 51:36application server after that you once
  1347. 51:39you have copied all the content you need
  1348. 51:40to restart the application server so
  1349. 51:43these two task you need to handle and to
  1350. 51:45handle these kind of a task with anible
  1351. 51:47you should use the anible handlers all
  1352. 51:50right I will not make the things
  1353. 51:51complicated so here onto the screen you
  1354. 51:53can see the anible playbook for my
  1355. 51:55anible Handler so the first task over
  1356. 51:58here is to set up the enginex
  1357. 52:00application server this is just an
  1358. 52:02example that's why I'm keeping the
  1359. 52:04things simple over here so my first task
  1360. 52:06is to install the engine server and
  1361. 52:08after that I'm just going to copy the
  1362. 52:10content or the HTML file which I just
  1363. 52:12want to update onto my application
  1364. 52:15server so this is the second task which
  1365. 52:17I will use to copy or to update the
  1366. 52:19content on my website now you might be
  1367. 52:21wondering like how should we incorporate
  1368. 52:23the anible handlers over here so here I
  1369. 52:26will will be using an attribute that is
  1370. 52:28notifi and that attribute we need to
  1371. 52:31Define what task it is going to do so
  1372. 52:33here the task which I'm going to do is
  1373. 52:35restart engine server because I have
  1374. 52:38already updated the index.html onto my
  1375. 52:41application server now you have used the
  1376. 52:43notify attribute inside your anible
  1377. 52:45playbook now you should Define that
  1378. 52:47particular task so that you can restart
  1379. 52:50the engine server and for that purpose
  1380. 52:52we are just going to use the Handler so
  1381. 52:54there is one more attribute which you
  1382. 52:56can see over over here is the Handler
  1383. 52:57and inside that Handler we are just
  1384. 52:59going to write the task to restart the
  1385. 53:01engine server all right so now you have
  1386. 53:04a little bit of understanding on what
  1387. 53:05the anible handlers are let's switch
  1388. 53:07over to the desktop and see the anible
  1389. 53:09playbook in demo let's start with the
  1390. 53:11demo and onto the screen you can see the
  1391. 53:13ncble Playbook but let's first start
  1392. 53:15with the project structure so on the
  1393. 53:17left hand side you can see this is the
  1394. 53:18ncble Handler project which I have
  1395. 53:20created and inside that anible handlers
  1396. 53:22project you will find inventory and the
  1397. 53:24roles trory so let's take take a look
  1398. 53:26onto the inventory directory where I
  1399. 53:28have defined the host file where I will
  1400. 53:30be storing the remote server IP address
  1401. 53:33or the remote server machine name so if
  1402. 53:35you open this file then you will find
  1403. 53:37the remote machine name over here just
  1404. 53:39ignore the line number two because I
  1405. 53:40have commented out all right so now we
  1406. 53:43have seen that we will be running the
  1407. 53:44anible Playbook onto this remote machine
  1408. 53:47this is my AWS ec2 instance but just
  1409. 53:49just you can just replace this uh
  1410. 53:51machine name with any IP address of your
  1411. 53:53remote server all right the next task is
  1412. 53:57the roles so here in the roles I have
  1413. 53:59created a role named Handler and
  1414. 54:01whenever you create a role then you need
  1415. 54:03to define the main. yml in any anible
  1416. 54:06paybook so here I have created the main.
  1417. 54:08yml so here I have written the task for
  1418. 54:11installing my application server which
  1419. 54:13is enginex which you can see over here
  1420. 54:15and here I have just written the second
  1421. 54:17task to copy the index.html the content
  1422. 54:20of my website and the third task which I
  1423. 54:23have written is to update the content of
  1424. 54:25my website so here I have here I'm just
  1425. 54:27trying to copy the updated HTML to the
  1426. 54:30destination directory so this is the uh
  1427. 54:32simplest anible Handler Playbook which I
  1428. 54:35have written it over here and in the
  1429. 54:37last task I'm just trying to call the
  1430. 54:39anible Handler so that it can restart
  1431. 54:42the engine server so this is an anible
  1432. 54:45Handler Playbook which I'll be using for
  1433. 54:47this particular demo now one thing I
  1434. 54:49forgot to show you is where I have
  1435. 54:50written the Handler so here you just
  1436. 54:53need to open the main Playbook that is
  1437. 54:54anible Handler Playbook IML and here I
  1438. 54:57have return the Handler which is restart
  1439. 54:59engine server so here you need to put
  1440. 55:02the correct name over here which is
  1441. 55:03restart Engen the same name I have used
  1442. 55:06inside this notify attribute which is
  1443. 55:09restart engine so you should put the
  1444. 55:11same name in the both the places okay so
  1445. 55:14coming back to the Handler so you need
  1446. 55:15to use the attribute Handler you need to
  1447. 55:17assign the name to the Handler and then
  1448. 55:19you need to do Define like what kind of
  1449. 55:22things you want to do with your handlers
  1450. 55:24so here I just wanted to restart the
  1451. 55:26engine service so the name uh the
  1452. 55:28attribute which I'm just going to use is
  1453. 55:30the engine service name over here and
  1454. 55:32the state is restarted which means anel
  1455. 55:35is going to instruct that please restart
  1456. 55:37this particular service so this is how
  1457. 55:40uh I'm just going to define or structure
  1458. 55:42my anible handlers Playbook and also
  1459. 55:44I'll put the GitHub repository link of
  1460. 55:46this particular repo into the
  1461. 55:48description section so feel free to copy
  1462. 55:50that particular raer to use this anible
  1463. 55:52Handler example now we have seen the
  1464. 55:54anible handlers uh Playbook example
  1465. 55:57let's try to run this particular anible
  1466. 55:59Playbook and just see how the things
  1467. 56:01works so just to give you a little bit
  1468. 56:03brief so first it is going to install
  1469. 56:05the engine server after that it is going
  1470. 56:07to copy that particular index.html and
  1471. 56:10as soon as we update that particular
  1472. 56:12index.html with updated content then it
  1473. 56:15should restart our genenic server so
  1474. 56:18that's the whole purpose of our anible
  1475. 56:20Handler because we just wanted to
  1476. 56:22restart something based on certain
  1477. 56:24action so that action is we have updated
  1478. 56:26the HTML content and that's for the
  1479. 56:29reason we need a restart to our engine X
  1480. 56:31server okay so this is my terminal and
  1481. 56:34I'm just going to run the ncble Playbook
  1482. 56:35command so here this is my ncble
  1483. 56:37playbook command so that's the keyword
  1484. 56:39that is ncble Playbook after that you
  1485. 56:41need to specify the name of the
  1486. 56:43inventory uh that's the inventory flag
  1487. 56:45which you first need to use and after
  1488. 56:47that you need to specify the host file
  1489. 56:49where your host file decides and if you
  1490. 56:52go back over here so here is the
  1491. 56:54inventory and this is the host file
  1492. 56:56where you have your remote server which
  1493. 56:57I have already mentioned okay Switching
  1494. 57:00back to the terminal so after that you
  1495. 57:02need to specify the name of the Playbook
  1496. 57:04so this is the name of the Playbook and
  1497. 57:05I can show you once again so this is my
  1498. 57:07anible Handler project and this is the
  1499. 57:09anible Handler Playbook which I'm using
  1500. 57:11right now so let's switch back to
  1501. 57:13terminal and this is the command which
  1502. 57:14I'll be executing to test my nzl Handler
  1503. 57:18so simply hit enter and if you're this
  1504. 57:21is the first time you're connecting to
  1505. 57:22your remote server then it is asking you
  1506. 57:24to do you really want to connect so
  1507. 57:25simply type yes all right so as you can
  1508. 57:28see my anible playbook had just finished
  1509. 57:30so let's start each task one by one so
  1510. 57:33here this is the first task update uh uh
  1511. 57:36at cache and install engine so this is
  1512. 57:38the first task which I have written so
  1513. 57:40let me open the Playbook so yeah this is
  1514. 57:42the first task which I just wanted to
  1515. 57:44execute and that will install the
  1516. 57:45enginex so if you go to the terminal so
  1517. 57:48here you can see this first task has
  1518. 57:50been executed second task is to copy the
  1519. 57:53index.html and remember this is the
  1520. 57:55first time we are copying the index.html
  1521. 57:58and we don't need to restart so that's
  1522. 58:00why uh this task will not call the
  1523. 58:02anible Handler so this is the second
  1524. 58:04task we just wanted to execute so just
  1525. 58:06check uh this is the index.html we just
  1526. 58:10wanted to copy and this index.html is
  1527. 58:13present into the same directory where I
  1528. 58:14have defined the task or the main. yml
  1529. 58:17all right let's go further after copying
  1530. 58:21the index.html the next task is to copy
  1531. 58:24the updated HTML to the destination
  1532. 58:26directory and just take a look so this
  1533. 58:28is the updated HTML which is present
  1534. 58:31into the same directory and I'm also I
  1535. 58:33just wanted to copy into the same
  1536. 58:35directory where my index.html is so it
  1537. 58:37will just rename this direct uh
  1538. 58:39particular file which is update. HTML to
  1539. 58:42the
  1540. 58:43index.html once it execute all right so
  1541. 58:46as soon as it copies the update. HTML it
  1542. 58:49should call the restart engine X Handler
  1543. 58:52so let's take a look onto the terminal
  1544. 58:54so here it is copying file first of all
  1545. 58:57and after that it is calling the restart
  1546. 58:59enginex Handler so let's take a look
  1547. 59:02onto the Handler so which is present
  1548. 59:04over here so this is the Handler and the
  1549. 59:06name of the task is restart engine so
  1550. 59:08let's take a look onto the terminal once
  1551. 59:10again so here you can see it is calling
  1552. 59:12the restart engine server Handler so
  1553. 59:15this is how this whole anible Playbook
  1554. 59:18work so where uh you have created or we
  1555. 59:21where you have installed the engine
  1556. 59:22server and then you have copied the
  1557. 59:24index.html then you have updated the
  1558. 59:27index.html and after the update you need
  1559. 59:29a restart and for that purpose you have
  1560. 59:32used the uh en Handler so well this is
  1561. 59:35just an idea which I just wanted to show
  1562. 59:38you like how the anible handlers work
  1563. 59:40but this idea can be used for any other
  1564. 59:43different use cases so the idea is
  1565. 59:45pretty simple like whenever you want to
  1566. 59:48execute something which is dependent on
  1567. 59:50some other task then you should use the
  1568. 59:52anible Handler so here the dependent
  1569. 59:55task was to
  1570. 59:56trigger the anible Handler when you
  1571. 59:58updated the particular content of the
  1572. 1:00:01file so here the content is index. stml
  1573. 1:00:04so as soon as I have updated the
  1574. 1:00:05index.html so I need to restart the
  1575. 1:00:08engine server so that's the dependency I
  1576. 1:00:10had between those tars so you have a if
  1577. 1:00:12you have a similar dependency in your
  1578. 1:00:15project then you could use the anible
  1579. 1:00:17handlers for your own purpose and it the
  1580. 1:00:20limitation of anable Handler is not up
  1581. 1:00:22to restarting a server you can trigger
  1582. 1:00:24the mail you can execute the bch so
  1583. 1:00:26there are a number of possibilities
  1584. 1:00:28which you can execute or which you can
  1585. 1:00:29Implement with the anible handlers I
  1586. 1:00:32hope you like the today's session onto
  1587. 1:00:33the anible Handler and how to use those
  1588. 1:00:36in the next session we will be taking a
  1589. 1:00:38look onto the anible variables so see
  1590. 1:00:40you into the next session of our anible
  1591. 1:00:42till then take care and
  1592. 1:00:45bye-bye hello there this is Rahul and
  1593. 1:00:48let's continue with our anible series
  1594. 1:00:50and in this session we are going to talk
  1595. 1:00:51about the anible variables so what we
  1596. 1:00:54are going to cover into this sensible
  1597. 1:00:56variable session so we will first start
  1598. 1:00:58with the very basic data types that is
  1599. 1:01:00string Boolean and then gradually we
  1600. 1:01:02will take a look onto the list and the
  1601. 1:01:04dictionaries also and furthermore into
  1602. 1:01:07this session we are also going to take a
  1603. 1:01:08look how to pass the variables at a
  1604. 1:01:10runtime using the command line and as
  1605. 1:01:12well as how to access the variables from
  1606. 1:01:14your vars file and at last we are going
  1607. 1:01:16to take a look onto the variables
  1608. 1:01:18precedence so this is going to be a
  1609. 1:01:20really comprehensive guide onto the
  1610. 1:01:21anible variables all right now switching
  1611. 1:01:23over to the desktop and onto this script
  1612. 1:01:25screen you can see this is the project
  1613. 1:01:27which I have created where I have
  1614. 1:01:28created a lots of variables and the
  1615. 1:01:31sample files over here so I'm just going
  1616. 1:01:33to share this link of this GitHub
  1617. 1:01:35repository into the description section
  1618. 1:01:37so feel free to use this project and you
  1619. 1:01:39can reference this example from this
  1620. 1:01:41GitHub repository let's start with a
  1621. 1:01:43very simple example so here onto the
  1622. 1:01:45screen you can see this is the Playbook
  1623. 1:01:46which I have written and the first
  1624. 1:01:48variable which I'm just going to create
  1625. 1:01:50is the string variable and here onto the
  1626. 1:01:52line number 11 you will see I have
  1627. 1:01:54created a variable and the the name of
  1628. 1:01:56the variable which I have kept over here
  1629. 1:01:58is the main Playbook variable so that's
  1630. 1:02:00the name of my variable and the value I
  1631. 1:02:02have assigned over here is the hellow
  1632. 1:02:04world from U main Playbook so this is
  1633. 1:02:06the simplest variable which I have
  1634. 1:02:08created inside my playbook and here if
  1635. 1:02:10you take a look carefully the line
  1636. 1:02:12number nine here I have to put vs as a
  1637. 1:02:15keyword inside your playbook so this is
  1638. 1:02:17the attribute which tells anle Playbook
  1639. 1:02:20that now everything below the vars or
  1640. 1:02:22inside the vs is going to be the
  1641. 1:02:24variables so this is the first way of
  1642. 1:02:27defining a variable inside a anible
  1643. 1:02:29Playbook now the question comes like how
  1644. 1:02:31you're going to use that anible variable
  1645. 1:02:33which you have created just now so here
  1646. 1:02:35inside the task which is line number 13
  1647. 1:02:38here I have created a task which is a
  1648. 1:02:40very simple task I keeping the Playbook
  1649. 1:02:42very simple over here and inside that I
  1650. 1:02:44have put a debug parameter over here and
  1651. 1:02:46inside that I have used that particular
  1652. 1:02:48variable so if you check the name of the
  1653. 1:02:50variable that is mainor Playbook _
  1654. 1:02:53variable so that's the name of my
  1655. 1:02:54variable and that's the variable which I
  1656. 1:02:56have used at line number 11 so this is
  1657. 1:02:58the simplest way you can create a
  1658. 1:03:00variable and you can use that particular
  1659. 1:03:02variable inside your task now how to
  1660. 1:03:04verify and how to test this Playbook so
  1661. 1:03:06there is a read me which I have already
  1662. 1:03:08created inside this anible project
  1663. 1:03:10example so here you can just run the
  1664. 1:03:13first Playbook command because this is
  1665. 1:03:14the simplest variable example which I'm
  1666. 1:03:17taking that's why you just use this
  1667. 1:03:18First Command over here and there are
  1668. 1:03:20couple of more example I have written
  1669. 1:03:22over here but those we will take a look
  1670. 1:03:24later but just to keep the simple this
  1671. 1:03:26is the command which I'm just going to
  1672. 1:03:27use to run my playbook and the command
  1673. 1:03:29is pretty simple if I can go over here
  1674. 1:03:32and if I do the softw then this is the
  1675. 1:03:35inventory where I'm putting my host file
  1676. 1:03:37but since this uh Playbook is running on
  1677. 1:03:39my Local Host so you don't really need
  1678. 1:03:41to have a remote server over there and
  1679. 1:03:44secondly this is the name of my playbook
  1680. 1:03:46that is ncble variable Playbook yml so
  1681. 1:03:49that's the name of my playbook which you
  1682. 1:03:50can see over here also so the Playbook
  1683. 1:03:52command uh Playbook run command is
  1684. 1:03:54pretty simple over here let's copy this
  1685. 1:03:56command from here and go to your
  1686. 1:03:59terminal so this is my terminal and I'm
  1687. 1:04:01just going to run this command over here
  1688. 1:04:03to execute my
  1689. 1:04:05playbook and here we need to verify the
  1690. 1:04:07task so the task which we were uh
  1691. 1:04:09referring to is string variable from
  1692. 1:04:11Main Playbook variable and here you can
  1693. 1:04:14see the output which I have printed the
  1694. 1:04:16value of that particular variable and
  1695. 1:04:19that the value is Hello World in main
  1696. 1:04:21Playbook so let's check back into our
  1697. 1:04:23anible Playbook so if you come over here
  1698. 1:04:25so this this is the name of the task
  1699. 1:04:26which we have just seen and the value of
  1700. 1:04:29the variable so this is how you're just
  1701. 1:04:31going to create a very simple variable
  1702. 1:04:33inside your playbook and you're just
  1703. 1:04:34going to use that Playbook or that
  1704. 1:04:36variable inside your playbook moving
  1705. 1:04:38further now we have seen the string
  1706. 1:04:40variable let's try to create an Boolean
  1707. 1:04:42variable so here onto the screen you can
  1708. 1:04:44see I have created a one more Boolean
  1709. 1:04:46variable and the name of the variable
  1710. 1:04:48which I have kept it is like is enabled
  1711. 1:04:50and the value I have assigned is true
  1712. 1:04:53and here at the line number 21 till 25
  1713. 1:04:55you can see this is how I'm just going
  1714. 1:04:57to use that particular Boolean variable
  1715. 1:04:59so the here is the name of my task which
  1716. 1:05:01you can keep anything and the message
  1717. 1:05:03which I'm just going to print over here
  1718. 1:05:05is variable is true but this message
  1719. 1:05:07will be printed when this uh particular
  1720. 1:05:09value of that particular variable is pro
  1721. 1:05:12so here you need to put a van condition
  1722. 1:05:14for the bullan variables So based on
  1723. 1:05:17this uh value of that particular bullan
  1724. 1:05:19variable this particular message will be
  1725. 1:05:21printed so here the value is true that
  1726. 1:05:23means our message should be printed onto
  1727. 1:05:25our cons
  1728. 1:05:26okay so I'm just going to open my
  1729. 1:05:27terminal over here and I'm just going to
  1730. 1:05:29run the same command which I have just
  1731. 1:05:31executed previously and just check the
  1732. 1:05:33uh
  1733. 1:05:34task and here you can see the task is
  1734. 1:05:36Boolean variable and the value which I
  1735. 1:05:38have got over here is Val variable is
  1736. 1:05:41true that means uh the True Value has
  1737. 1:05:43been satisfied and I'm able to print the
  1738. 1:05:45message I'm just going to clear the
  1739. 1:05:47screen and next thing I'm just going to
  1740. 1:05:48do I'm just going to set the value to
  1741. 1:05:50the false and let's verify the task once
  1742. 1:05:52again so here just go back to the
  1743. 1:05:55Playbook and set the value to false and
  1744. 1:05:58go to terminal and rerun the same
  1745. 1:06:00command over here so here you can see uh
  1746. 1:06:04so Boolean variable task has been
  1747. 1:06:06executed but nothing got printed over
  1748. 1:06:08here into the message so that means uh
  1749. 1:06:11this is how uh bullan is evaluated based
  1750. 1:06:13on true and false if you set the value
  1751. 1:06:15to true then that particular message is
  1752. 1:06:17getting printed and if you set it to the
  1753. 1:06:19false then that particular message is
  1754. 1:06:21not going to print moving to the next
  1755. 1:06:22variable which is our list and here you
  1756. 1:06:25can see uh line number 17 till line
  1757. 1:06:27number 20 we have created a variable
  1758. 1:06:29that is list and the name of the list is
  1759. 1:06:31fruits and inside that particular list I
  1760. 1:06:33have added three uh fruits actually
  1761. 1:06:36apple banana and orange so this is how
  1762. 1:06:38you are just going to create a list
  1763. 1:06:39variable inside your anible and the task
  1764. 1:06:43is going to be pretty much same so here
  1765. 1:06:45I have created a task where I'm just
  1766. 1:06:46going to use that particular variable
  1767. 1:06:48and here the name of the variable which
  1768. 1:06:50I have used over here is fruits so let's
  1769. 1:06:52verify this particular variable go back
  1770. 1:06:55to terminal and run the command and here
  1771. 1:06:59you can see uh we have printed the name
  1772. 1:07:01or the list of fruit variables over here
  1773. 1:07:04now we have seen the list variable but
  1774. 1:07:06is there possibility in anible to access
  1775. 1:07:09the index position or a particular
  1776. 1:07:11element in the particular list so here
  1777. 1:07:13we have created a list of fruits but if
  1778. 1:07:16I want to access the particular element
  1779. 1:07:18inside that list then how can I do that
  1780. 1:07:21so nle provides a way and you need to
  1781. 1:07:24use the index position so so here you
  1782. 1:07:25can see I have created a one more task
  1783. 1:07:27and inside that task I have uh specified
  1784. 1:07:30the position of that particular element
  1785. 1:07:32which I want to access inside the list
  1786. 1:07:34so here I have mentioned zero so which
  1787. 1:07:36means I'm trying to access the Apple uh
  1788. 1:07:39uh fruit inside that particular list so
  1789. 1:07:41let's go back to the terminal and verify
  1790. 1:07:43whether it works or not so I'll just
  1791. 1:07:46clear the screen and I run the Playbook
  1792. 1:07:49and here you can see uh the previous
  1793. 1:07:51task where we have printed all the
  1794. 1:07:52element present inside the list and in
  1795. 1:07:55in in this task we are just printing
  1796. 1:07:57that particular element which is present
  1797. 1:07:59inside the list and that is Apple so
  1798. 1:08:01this is how you can access the elements
  1799. 1:08:03uh inside the list with the index
  1800. 1:08:05positions moving to the next variable
  1801. 1:08:07and this time we are going to take an
  1802. 1:08:09example of a dictionary variable so here
  1803. 1:08:11onto the screen you can see from the
  1804. 1:08:12line number 22 till 26 I have created a
  1805. 1:08:15dictionary and what is dictionary so
  1806. 1:08:17here this is the name of the dictionary
  1807. 1:08:19that is fruit prices and inside that
  1808. 1:08:22dictionary you will see the price of
  1809. 1:08:23Apple uh with its value
  1810. 1:08:26but just remember from the previous
  1811. 1:08:27thing so previous uh list variable was
  1812. 1:08:30only containing a list of a single
  1813. 1:08:32element so that is apple banana oranges
  1814. 1:08:35there was no price associated with it
  1815. 1:08:37but here in the dictionary you have a
  1816. 1:08:39dictionary name that is fruit prices and
  1817. 1:08:41inside that dictionary you will find the
  1818. 1:08:43name of the fruit along with its prices
  1819. 1:08:46so this is how we are just going to
  1820. 1:08:47create a dictionary inside the anible
  1821. 1:08:49Playbook let's scroll further down into
  1822. 1:08:52the Playbook and print the value of a
  1823. 1:08:53dictionary so here I have created a one
  1824. 1:08:55more task that is dictionary variable
  1825. 1:08:57and accessing the value of the those
  1826. 1:08:59particular dictionaries and this is the
  1827. 1:09:01name of that particular dictionary
  1828. 1:09:03variable which I'm going to use so I'm
  1829. 1:09:05just going to head back to terminal and
  1830. 1:09:07I'm just going to run the Playbook once
  1831. 1:09:10again and here you can see the
  1832. 1:09:12dictionary variable task has been
  1833. 1:09:14executed successfully and here I can see
  1834. 1:09:16the values of my particular dictionary
  1835. 1:09:18so this is how you are going to create a
  1836. 1:09:20dictionary and this is how you're going
  1837. 1:09:21to access that particular dictionary
  1838. 1:09:23variable inside your playbook now let's
  1839. 1:09:25play around this dictionary variable so
  1840. 1:09:27I'll scroll up and here you can see this
  1841. 1:09:29is the dictionary we are having so what
  1842. 1:09:31if is there any possibility to access
  1843. 1:09:34that particular element inside that
  1844. 1:09:36dictionary so here I would like to
  1845. 1:09:38access only Apple so is it possible so
  1846. 1:09:41my answer is yes anible provides you a
  1847. 1:09:43way to access a particular element
  1848. 1:09:45present inside the dictionary so here uh
  1849. 1:09:48I have created a one more task for
  1850. 1:09:50accessing that particular variable that
  1851. 1:09:51is Apple inside the dictionary so what
  1852. 1:09:54you need to do is you just need to
  1853. 1:09:55create the task with the name and then
  1854. 1:09:57you need to uh put the variable uh of
  1855. 1:10:00variable name of that particular
  1856. 1:10:02dictionary along with the particular
  1857. 1:10:04element name that is Apple so that's how
  1858. 1:10:07you're going to access that particular
  1859. 1:10:08element which is present inside that
  1860. 1:10:10particular dictionary so I'm just going
  1861. 1:10:12to head over to terminal to verify this
  1862. 1:10:14so let's head over here and run the
  1863. 1:10:17Playbook and here you can see uh the
  1864. 1:10:19dictionary variable accessing individual
  1865. 1:10:22specific field so here you can see the
  1866. 1:10:23value of that particular element element
  1867. 1:10:25that is Apple and that is 0.5 so this is
  1868. 1:10:28how you're just going to access that
  1869. 1:10:29particular element which is present
  1870. 1:10:31inside your dictionary and this concept
  1871. 1:10:33is pretty much same uh if you compare
  1872. 1:10:35with the list when you're trying to
  1873. 1:10:36access the Apple present inside that
  1874. 1:10:38list so this is how you're going to uh
  1875. 1:10:40use that particular accessing of that
  1876. 1:10:42particular element inside the dictionary
  1877. 1:10:44now I'm just going to take a one more
  1878. 1:10:46example on top of that particular
  1879. 1:10:48dictionary so where I'm just going to
  1880. 1:10:49take a one more variable so if you are
  1881. 1:10:52familiar with any programming languages
  1882. 1:10:54then you create a multi variables and
  1883. 1:10:56then you assign a particular value of
  1884. 1:10:58that variable to any other variable so
  1885. 1:11:01here uh we have created a dictionary and
  1886. 1:11:03from that dictionary I'm just going to f
  1887. 1:11:05the value of that apple and then assign
  1888. 1:11:08that value to another variable so here
  1889. 1:11:10onto the screen you can see the line
  1890. 1:11:12number 54 till 57 so here I'm just
  1891. 1:11:15trying to fetch the value of that
  1892. 1:11:17particular apple and then assign that
  1893. 1:11:19value of that particular variable to
  1894. 1:11:21another variable so that we call it as a
  1895. 1:11:23register variable in place and so here
  1896. 1:11:27you need to use the keyword register so
  1897. 1:11:29that you can register that particular
  1898. 1:11:31variable and this particular value which
  1899. 1:11:33is present over here is going to be
  1900. 1:11:35assigned to this particular variable and
  1901. 1:11:37to verify this what we are going to do
  1902. 1:11:39we are just going to put or we are just
  1903. 1:11:41going to print that value of that
  1904. 1:11:43registered variable so here I'm just
  1905. 1:11:45going to print it onto my command line
  1906. 1:11:47so this is how you are going to do the
  1907. 1:11:49variable assignment to any other
  1908. 1:11:51variable using the registered variable
  1909. 1:11:53in the nle Playbook okay let's let's
  1910. 1:11:55open the terminal and run the Playbook
  1911. 1:11:57to verify the value so I'm just going to
  1912. 1:11:58clear this one and run the
  1913. 1:12:01Playbook and here you can see uh the get
  1914. 1:12:04the price of an apple and print the
  1915. 1:12:06value of a registered variable so this
  1916. 1:12:09particular task here you can see there
  1917. 1:12:11is nothing got printed so if you can
  1918. 1:12:13check over here so in this particular
  1919. 1:12:15task we are just doing the assignment we
  1920. 1:12:17are not trying to print anything so we
  1921. 1:12:19are just trying to assign the value of
  1922. 1:12:21Apple to the registered variable and
  1923. 1:12:23after that in the next task which is the
  1924. 1:12:25print the value of a registered variable
  1925. 1:12:27where we are just going to print the
  1926. 1:12:28value of that particular registered
  1927. 1:12:30variable so which is which you can see
  1928. 1:12:32and verify from this particular terminal
  1929. 1:12:35so this is how you're just going to play
  1930. 1:12:36around with a multiple variable
  1931. 1:12:38assignment into your an Playbook all
  1932. 1:12:40right so now we have seen the uh
  1933. 1:12:42register variable in anible let's
  1934. 1:12:45increase the complexity of a variables a
  1935. 1:12:47little bit more and here we are just
  1936. 1:12:48going to play around with a couple of
  1937. 1:12:50dictionaries so the first dictionary we
  1938. 1:12:52will take is the for price list and the
  1939. 1:12:55second dictionary which I'm just going
  1940. 1:12:56to test uh which I'm just going to take
  1941. 1:12:58is the nested variable dictionary over
  1942. 1:13:01here so here you can see this is the
  1943. 1:13:03fruit basket and this is the first
  1944. 1:13:05element uh inside that particular fruit
  1945. 1:13:07basket and there is a name and then
  1946. 1:13:09inside that there is a particular list
  1947. 1:13:11of fruits which is apple and orange and
  1948. 1:13:13similarly there is one more fruit basket
  1949. 1:13:15for Yen and there are fruits like banana
  1950. 1:13:18and apple inside that fruit basket so
  1951. 1:13:21what I'm just going to do there is a
  1952. 1:13:22scenario which I'm just going to take so
  1953. 1:13:24first of all I'm just going to fetch the
  1954. 1:13:26fruit basket then I'm just going to
  1955. 1:13:28fetch the uh first element that is the
  1956. 1:13:31John's basket and inside that basket I'm
  1957. 1:13:34just going to fetch the apple and after
  1958. 1:13:37fetching this particular fruit from this
  1959. 1:13:39basket I'm just going to use the fruit
  1960. 1:13:41price list to fetch the prices of that
  1961. 1:13:44particular Apple so that's the scenario
  1962. 1:13:47and I just wanted to show you that this
  1963. 1:13:48is how you're just going to mass around
  1964. 1:13:50the dictionaries and you're just going
  1965. 1:13:52to iterate on those particular complex
  1966. 1:13:54dictionaries all right so now how to
  1967. 1:13:56achieve that so if you go down into the
  1968. 1:13:58task so here I have created a particular
  1969. 1:14:00task and this task is pretty simple but
  1970. 1:14:03uh just to give you the context so first
  1971. 1:14:05of all I'm just going to access the
  1972. 1:14:06fruit basket so that is this fruit fruit
  1973. 1:14:09basket and if you go up over here so
  1974. 1:14:12this is the fruit basket and here I'm
  1975. 1:14:13just trying to access the zeroth element
  1976. 1:14:16that is John's basket so I'm just going
  1977. 1:14:18to put zero and after that I'm just
  1978. 1:14:20going to put one more zero into the
  1979. 1:14:22fruits so let's go here and and here you
  1980. 1:14:25can see the fruit basket I just wanted
  1981. 1:14:27to access the John's fruit basket and
  1982. 1:14:30after that in the fruits basket I'm just
  1983. 1:14:32going to access the zero element that is
  1984. 1:14:35Apple so this particular uh this
  1985. 1:14:38particular expression is going to return
  1986. 1:14:40me apple and once I get that particular
  1987. 1:14:43value that is Apple then I'm just going
  1988. 1:14:44to apply it to the fruit prices so that
  1989. 1:14:47is our again uh if you go up over here
  1990. 1:14:49that fruit prices is again another
  1991. 1:14:51dictionary and inside the dictionary I'm
  1992. 1:14:53just going to mention that I I just
  1993. 1:14:55wanted to fetch the Apple so this
  1994. 1:14:58particular whole expression is going to
  1995. 1:15:01return me apple and once that has been
  1996. 1:15:04return returned and then this expression
  1997. 1:15:05is going to return me 0.5 which is the
  1998. 1:15:08value of that particular Apple all right
  1999. 1:15:10so now we have seen like how to use that
  2000. 1:15:13particular uh expression and access the
  2001. 1:15:15nasted element inside the dictionary so
  2002. 1:15:17let's run I'll just undo the task and
  2003. 1:15:19let's go to terminal and run this thing
  2004. 1:15:22I'll just clear
  2005. 1:15:23it
  2006. 1:15:25and run it and here you can see uh where
  2007. 1:15:29it is yeah get the value of a apple from
  2008. 1:15:31a nested variable so that was the task
  2009. 1:15:33and which you can see over here get the
  2010. 1:15:35value from a nested variable and if I go
  2011. 1:15:38back to terminal once again so here you
  2012. 1:15:39can see the value of that particular uh
  2013. 1:15:42fruit which is Apple so this is how we
  2014. 1:15:44just going to access the nested elements
  2015. 1:15:47inside the uh dictionary all right so
  2016. 1:15:49now we are bit familiar with the uh our
  2017. 1:15:52dictionary variable and the nested
  2018. 1:15:53dictionary variable and how to access
  2019. 1:15:55them the next thing which I'm just going
  2020. 1:15:57to show you is the Ginger 2 filters so
  2021. 1:16:00here uh this is the task which I have
  2022. 1:16:01created for Ginger 2 filters and these
  2023. 1:16:03Ginger to filters are really helpful
  2024. 1:16:05when you when you want to do some kind
  2025. 1:16:07of a string manipulation like converting
  2026. 1:16:09lower case to upper case so these Ginger
  2027. 1:16:11to filters are really handy but that's
  2028. 1:16:14converting to lower case and uppercase
  2029. 1:16:16is just one example or one use case but
  2030. 1:16:18there are and number of application of
  2031. 1:16:20Ginger 2 filter so the idea is just to
  2032. 1:16:23learn the concept of a ginger two
  2033. 1:16:25filters over here so here what I'm going
  2034. 1:16:27to do I'm just going to create I'm just
  2035. 1:16:29going to access the keys of my fruit
  2036. 1:16:31prices so if you go over here so this is
  2037. 1:16:34our fruit prices dictionary and the keys
  2038. 1:16:36are apple banana and orange so I'm just
  2039. 1:16:38going to access only the keys after that
  2040. 1:16:41I'm just going to convert that
  2041. 1:16:43particular keys to the list so here if
  2042. 1:16:45you see the pipe then this pipe is a
  2043. 1:16:47Ginger 2 filter which is converting this
  2044. 1:16:50particular keys to list after that I'm
  2045. 1:16:54just going to use a again the same
  2046. 1:16:55Ginger to filter and convert it into
  2047. 1:16:57uppercase so this is how I'm just going
  2048. 1:16:59to do the uppercase conversion of my
  2049. 1:17:01keys and finally I'm just going to print
  2050. 1:17:03it in I'm just going to convert it into
  2051. 1:17:05again a list and this particular task is
  2052. 1:17:07going to print the value of that
  2053. 1:17:09particular list now let's run this
  2054. 1:17:11particular Playbook once again and I'm
  2055. 1:17:13just going to oh the screen is already
  2056. 1:17:15clear so I'm just going to run the
  2057. 1:17:16Playbook
  2058. 1:17:17command and here you can see using the
  2059. 1:17:20ginger to filters on variables so this
  2060. 1:17:22is the name of the keys like apple
  2061. 1:17:24banana orange and which got converted
  2062. 1:17:26into the uppercase and these are Now
  2063. 1:17:28list these are not dictionaries anymore
  2064. 1:17:30so this is how you're just going to use
  2065. 1:17:32the ginger to filters inside your anible
  2066. 1:17:34playbook moving further so till now you
  2067. 1:17:37have seen like how to create the
  2068. 1:17:38variables inside your ncble playbook and
  2069. 1:17:41how to access those particular variable
  2070. 1:17:43now if I talk about the scenario if you
  2071. 1:17:46want to create a variable inside a
  2072. 1:17:48different Wars file and you don't want
  2073. 1:17:50to create the variable inside the same
  2074. 1:17:52Playbook so then how you're going to do
  2075. 1:17:54that so if you take the next example
  2076. 1:17:56which I'm just going to show you over
  2077. 1:17:57here so this is the sixth example which
  2078. 1:18:00I'm just taking where I'm just going to
  2079. 1:18:01declare the variable or I'm just going
  2080. 1:18:03to create the variable in a different
  2081. 1:18:04Wars file so the name of the file is my
  2082. 1:18:07wars. yml and if I open that file so
  2083. 1:18:11inside this anible variable project that
  2084. 1:18:13there is a file which exists like my
  2085. 1:18:15wars. yml and here I have created that
  2086. 1:18:18particular variable so this is the name
  2087. 1:18:19of my variable that is vs from my my
  2088. 1:18:22Wars yml so this is just a very a dummy
  2089. 1:18:25name I have taken and this is the value
  2090. 1:18:27which I have assigned to that particular
  2091. 1:18:28variable so this particular variable
  2092. 1:18:30doesn't exist into my main Playbook but
  2093. 1:18:33it exist into a separate Wars or
  2094. 1:18:35variables
  2095. 1:18:36file so how to access those particular
  2096. 1:18:40variables so first of all you need to
  2097. 1:18:41specify the reference or the location of
  2098. 1:18:44that particular variable or the wars
  2099. 1:18:46file so here you need to first use the
  2100. 1:18:48attribute that is vs file and here you
  2101. 1:18:50can specify the variable file name that
  2102. 1:18:53is my wars. y
  2103. 1:18:55and here you can reference or you can
  2104. 1:18:57include multiple Wars files so if you
  2105. 1:18:59have more than one file then you can
  2106. 1:19:01just keep on adding a more uh the vs
  2107. 1:19:04file name over here and anel will be
  2108. 1:19:06able to include those variables file
  2109. 1:19:08inside your playbook so here I have just
  2110. 1:19:10taken a one example so here there is a
  2111. 1:19:12one file and inside that I have created
  2112. 1:19:14a one variable and how to access that
  2113. 1:19:17particular variable so accessing part is
  2114. 1:19:19still the same your task is going to be
  2115. 1:19:21look like still the same so here I have
  2116. 1:19:23just created a one more task and here I
  2117. 1:19:25have used the variable that is vs from
  2118. 1:19:27my Wars file so if you copy this and if
  2119. 1:19:29you go over here then you should be able
  2120. 1:19:31to find it so this is the variable which
  2121. 1:19:33I'm trying to access it all right so now
  2122. 1:19:36you have seen this particular example
  2123. 1:19:37let's go to terminal and execute it so
  2124. 1:19:40I'll clear
  2125. 1:19:43it and here you can see this is the name
  2126. 1:19:46of the variable and this is the value of
  2127. 1:19:48that particular variable so idea was
  2128. 1:19:50over here is like how to include or how
  2129. 1:19:53to use the variable file which is
  2130. 1:19:55external not external but at least
  2131. 1:19:56present into the different directory of
  2132. 1:19:58that particular project and references
  2133. 1:20:00into your anle playable so this is how
  2134. 1:20:03your just going to do the inclusion of
  2135. 1:20:05that particular variable file all right
  2136. 1:20:08so now we have seen like how to create a
  2137. 1:20:09variable inside the Playbook how to
  2138. 1:20:11create a variable inside a variable file
  2139. 1:20:14but next thing which I'm just going to
  2140. 1:20:15show you like how to pass the variable
  2141. 1:20:18at run time so here I have just created
  2142. 1:20:21a one task the task is pretty simple
  2143. 1:20:23again so this is the name of the task
  2144. 1:20:25and this is the value of that variable
  2145. 1:20:26version but the key thing over here is
  2146. 1:20:29that I have not declared this version
  2147. 1:20:30variable inside this Playbook so if you
  2148. 1:20:33will not just find any reference over
  2149. 1:20:35here if you go to the top over so here
  2150. 1:20:37you can see there is no reference to
  2151. 1:20:39that version variable and if you go to
  2152. 1:20:41the my WS files over here then also
  2153. 1:20:43there is no reference to the version
  2154. 1:20:45variable so this particular version
  2155. 1:20:47variable which you see over here uh at
  2156. 1:20:50line number 96 so this version variable
  2157. 1:20:53I have not declared anywhere here but
  2158. 1:20:55I'm just going to pass that particular
  2159. 1:20:57value of that variable at run time and
  2160. 1:21:00how to do that so if you open this
  2161. 1:21:02particular readme file so till now we
  2162. 1:21:04were just simply executing this anible
  2163. 1:21:06Playbook but here at the line number 10
  2164. 1:21:09this is the Playbook command which I'm
  2165. 1:21:11just going to use to pass the variable
  2166. 1:21:13at run time and to do that you what you
  2167. 1:21:16need to do you just need to add extra
  2168. 1:21:19flags that is extra vars for extra
  2169. 1:21:21variable and here you need to specify
  2170. 1:21:23the name of the variable that is version
  2171. 1:21:25and its value and similarly you can pass
  2172. 1:21:28one more variable other variable and the
  2173. 1:21:30value that is who so here you can pass
  2174. 1:21:33the runtime variable to your anible
  2175. 1:21:35playbook and you cannot just only pass
  2176. 1:21:37one variable but you can pass multiple
  2177. 1:21:39variables let's copy this command from
  2178. 1:21:41this particular R me and go to your
  2179. 1:21:44terminal over here and clear the screen
  2180. 1:21:47and paste the
  2181. 1:21:49command and here you can see get the
  2182. 1:21:51value from a runtime and if you go back
  2183. 1:21:54over here here so get the value from the
  2184. 1:21:56runtime and the variable is version and
  2185. 1:21:58you can see the value that is 1.0 and if
  2186. 1:22:02I show you the again the readme file
  2187. 1:22:04then you can see 1.0 so this is how
  2188. 1:22:07you're just going to pass the Val uh
  2189. 1:22:09variable at a run time using your ncble
  2190. 1:22:11playbook command and you can access the
  2191. 1:22:13same variable inside your playbook all
  2192. 1:22:15right so now we have seen like how to
  2193. 1:22:17pass the variable at a runtime from the
  2194. 1:22:19command line the next concept I'm
  2195. 1:22:21talking about is can you pass the
  2196. 1:22:23variable file from the command line so
  2197. 1:22:26yes you can do that in your anible
  2198. 1:22:28playbook so here I have already created
  2199. 1:22:30a my Wars file that is present inside my
  2200. 1:22:33project and inside that war file I have
  2201. 1:22:35created a variable that is other
  2202. 1:22:37variable and the value is four so here
  2203. 1:22:40what I'm going to do I'm just going to
  2204. 1:22:41print the value of other variable but
  2205. 1:22:44I'm just going to run my ncble playbook
  2206. 1:22:46command a little bit different so here
  2207. 1:22:48in the read me you will find a one more
  2208. 1:22:50command and here I have used the extra
  2209. 1:22:53vars and here I have pass the yml file
  2210. 1:22:56so instead of passing an runtime
  2211. 1:22:58variable individually I'm just going to
  2212. 1:23:00pass the complete yml file name at
  2213. 1:23:03runtime so this is the way you should do
  2214. 1:23:06it and you can even pass the Json file
  2215. 1:23:08also so what you need to do you just
  2216. 1:23:09need to put at the red sign and after
  2217. 1:23:11dat the name of that particular file but
  2218. 1:23:13always remember try to put the correct
  2219. 1:23:15path so if this file is present inside
  2220. 1:23:17some of the directory then just use that
  2221. 1:23:20particular path relative to that your
  2222. 1:23:22anible label but anyway this Playbook is
  2223. 1:23:25available over here and uh this yml is
  2224. 1:23:28also available onto the same level so
  2225. 1:23:30I'm just going to go to terminal I'm
  2226. 1:23:32just going to clear the screen and I'm
  2227. 1:23:34just going to run the
  2228. 1:23:35command and here you can see the value
  2229. 1:23:38has been printed the other variable F
  2230. 1:23:40and the print the value of a variable
  2231. 1:23:42when v file is passed at a run time so
  2232. 1:23:44that's the name of that particular task
  2233. 1:23:47so this is how you're just going to uh
  2234. 1:23:49create uh not create but uh you're just
  2235. 1:23:51going to pass the variable uh from the
  2236. 1:23:53command line so this is what I just
  2237. 1:23:55wanted to show you uh this is one more
  2238. 1:23:58example where you can use the runtime
  2239. 1:23:59variables now the last thing which I
  2240. 1:24:01just wanted to cover into this variable
  2241. 1:24:03session is the variable precedence so
  2242. 1:24:05how the variable precedence happen when
  2243. 1:24:07you have multiple variables with the
  2244. 1:24:09same name so let's take an example to
  2245. 1:24:12understand this so in the my Wars files
  2246. 1:24:14I have created a variable that is other
  2247. 1:24:16variable with the value F but in the
  2248. 1:24:19readme file at a runtime I'm just
  2249. 1:24:21passing the same variable with the value
  2250. 1:24:23f world so again I'm using the same
  2251. 1:24:26variable but I'm trying to pass the two
  2252. 1:24:29values one is present from the wars file
  2253. 1:24:31and one is present or one is I'm passing
  2254. 1:24:33it from the runtime from my command line
  2255. 1:24:36so which precedence or which value will
  2256. 1:24:38be getting uh printed once I run and
  2257. 1:24:41execute this particular task so the
  2258. 1:24:43answer is if you pass anything from the
  2259. 1:24:45command line or from the runtime which
  2260. 1:24:47is present over here will'll get the
  2261. 1:24:49Precedence so that's the priority of the
  2262. 1:24:52variable if you pass anything from the
  2263. 1:24:54command line then that variable value
  2264. 1:24:56will always be used inside your n
  2265. 1:24:59Playbook so let's run this and see this
  2266. 1:25:01uh in action so I'll just head over to
  2267. 1:25:03terminal and let me first copy this
  2268. 1:25:05particular
  2269. 1:25:07command go to terminal I'll create the
  2270. 1:25:11screen and pest it over
  2271. 1:25:14here and here you can see uh this is the
  2272. 1:25:17value which got printed that is f world
  2273. 1:25:19but here in the wars file the value was
  2274. 1:25:22F so it will always override if you pass
  2275. 1:25:25anything at a runtime then it will
  2276. 1:25:27always override the values which is
  2277. 1:25:29present uh inside your ncble Playbook or
  2278. 1:25:31if you have created a variable inside
  2279. 1:25:33your Wars file so runtime is always get
  2280. 1:25:36the precedence over any other variable
  2281. 1:25:39so that's the Precedence order I just
  2282. 1:25:40wanted to show you inside this uh Anu
  2283. 1:25:43Playbook all right so that's what I just
  2284. 1:25:46wanted to show you into the today's
  2285. 1:25:47session on anible variable but in the
  2286. 1:25:49next session which is going to be a
  2287. 1:25:51little bit short session because you are
  2288. 1:25:53already familiar with the variables but
  2289. 1:25:55in the next session we're going to talk
  2290. 1:25:56about the environment variables and how
  2291. 1:25:58to use those environment variable inside
  2292. 1:26:00your anible clickbook so that's going to
  2293. 1:26:02be the next session and after that we
  2294. 1:26:04are just going to talk more about the if
  2295. 1:26:06then else statement and how to use those
  2296. 1:26:08if then else statement inside your
  2297. 1:26:09anable play so stay tuned and see you
  2298. 1:26:12into the next session of anible and if
  2299. 1:26:14you're interested in any other devop
  2300. 1:26:16topic like like terraform kubernetes
  2301. 1:26:18then please go out and check my channel
  2302. 1:26:20where I have uploaded those sessions so
  2303. 1:26:22till then take care and bye-bye
  2304. 1:26:25hello and welcome back like in the
  2305. 1:26:27previous session we have talked about
  2306. 1:26:29the anible variables but in this lab
  2307. 1:26:32session we are going to talk about the
  2308. 1:26:33environment variables now when we are
  2309. 1:26:35talking about the environment variables
  2310. 1:26:37then I'm talking about the path home and
  2311. 1:26:40user so this is just an example of
  2312. 1:26:42environment variables which are
  2313. 1:26:44generally available onto the environment
  2314. 1:26:46so anible Playbook allows you to update
  2315. 1:26:49and use those environment variables when
  2316. 1:26:51you are writing your own Playbook so
  2317. 1:26:53with the help of anel you can set the
  2318. 1:26:55custom environment variable which is
  2319. 1:26:57needed for your anible playbook and
  2320. 1:27:00those environment variables can be set
  2321. 1:27:02at a task level or you can set it on
  2322. 1:27:04that particular Global or the Playbook
  2323. 1:27:06level all right so now I switch to my
  2324. 1:27:08desktop uh let me zoom in over
  2325. 1:27:11here and here this is the Playbook which
  2326. 1:27:13I have created to explain the
  2327. 1:27:15environment variable so first of all
  2328. 1:27:17what we are going to do first of all we
  2329. 1:27:18are just going to create this
  2330. 1:27:19environment variable at very top level
  2331. 1:27:22or anible Playbook level so that this
  2332. 1:27:24environment variable which I have
  2333. 1:27:26declared over here will be accessible
  2334. 1:27:28for all the task which is mentioned
  2335. 1:27:29inside my playbook second we are just
  2336. 1:27:32going to create a one more environment
  2337. 1:27:34variable which is present inside the
  2338. 1:27:36task and the visibility and the scope of
  2339. 1:27:38that environment variable is only within
  2340. 1:27:41this particular task and this cannot be
  2341. 1:27:43accessed outside of that particular task
  2342. 1:27:46so that's these are the two use cases
  2343. 1:27:48which we are going to see in this demo
  2344. 1:27:50okay let me break this anible Playbook
  2345. 1:27:52and first of all we'll start with like
  2346. 1:27:54how to create an environment variable so
  2347. 1:27:56at line number nine you will see a
  2348. 1:27:57keyword or attribute that is named
  2349. 1:27:59environment and below that you will find
  2350. 1:28:02the line where I have written a variable
  2351. 1:28:04name that is example and the value I
  2352. 1:28:06have assigned over here is fuar so this
  2353. 1:28:09example name is user defined name you
  2354. 1:28:11can keep a environment variable name of
  2355. 1:28:13your choice so here you can uh keep a
  2356. 1:28:15one more variable name like a my V one
  2357. 1:28:19and you can assign the value to it also
  2358. 1:28:21so that will also work so I can put VAR
  2359. 1:28:24varable
  2360. 1:28:26value
  2361. 1:28:29one so that also works so here you can
  2362. 1:28:31create a multiple number of environment
  2363. 1:28:33variable but what's the key thing over
  2364. 1:28:36here is this environment variable like
  2365. 1:28:38example and my wi one these two
  2366. 1:28:41environment variables are available for
  2367. 1:28:43all the task which I'm going to create
  2368. 1:28:46or which I have already defined inside
  2369. 1:28:48my playbook so these variables can be
  2370. 1:28:50accessed throughout these all these
  2371. 1:28:52tasks so that's the key benefit which
  2372. 1:28:54you will get if you define the
  2373. 1:28:55environment variable in this fashion now
  2374. 1:28:58second thing like uh if you want to
  2375. 1:29:00define a environment variable which is
  2376. 1:29:02not Global but which is very specific to
  2377. 1:29:05a particular
  2378. 1:29:06task so over here in this section so
  2379. 1:29:09here I have created a variable or a task
  2380. 1:29:12uh sorry it's not variable it's a task
  2381. 1:29:14so environment variable for only task
  2382. 1:29:16level so here I have created again the
  2383. 1:29:18same like I have used the keyword
  2384. 1:29:20attribute that is environment and the
  2385. 1:29:21variable name that is my task level
  2386. 1:29:23variable
  2387. 1:29:24and I have assigned the value that is
  2388. 1:29:26hello world so now we have two
  2389. 1:29:28environment variable maybe we can say 3
  2390. 1:29:31environment variable example mayware one
  2391. 1:29:34and then this is the third one which is
  2392. 1:29:35very specific to that particular task
  2393. 1:29:38and here what we are doing for each task
  2394. 1:29:40we are printing the value so here you
  2395. 1:29:41can see I'm just printing the value of
  2396. 1:29:43example which is like a global
  2397. 1:29:45environment variable and here I'm just
  2398. 1:29:47trying to print the value which is like
  2399. 1:29:49a task level environment variable which
  2400. 1:29:51is this one and the third thing uh I
  2401. 1:29:54just wanted to demonstrate like I just
  2402. 1:29:56wanted to access I just wanted to access
  2403. 1:29:58the both variable that is example which
  2404. 1:30:01is this as well as this uh like a task
  2405. 1:30:03level environment variable which is this
  2406. 1:30:05one so ideally uh this particular task
  2407. 1:30:08we should only get the value of this
  2408. 1:30:10variable but not this one because this
  2409. 1:30:13my task level variable is a task level
  2410. 1:30:15uh environment variable and I cannot
  2411. 1:30:18access it because it is outside of this
  2412. 1:30:20part uh outside of the scope of that
  2413. 1:30:22particular task so these are the three
  2414. 1:30:25tasks which I have created uh let's
  2415. 1:30:27switch over to terminal and run this
  2416. 1:30:29playable all right so this is my
  2417. 1:30:30terminal and this is the command which
  2418. 1:30:32I'm just going to run but in case if you
  2419. 1:30:34are wondering like where to find this
  2420. 1:30:35command then I have created this readme
  2421. 1:30:37file over here inside this particular
  2422. 1:30:39project so from here you can just copy
  2423. 1:30:41this particular command and this whole
  2424. 1:30:43repository I'll post it onto my
  2425. 1:30:45description section so you can clone
  2426. 1:30:47this particular repository okay so
  2427. 1:30:49coming back to my terminal which is over
  2428. 1:30:51here so I'm just going to add one more
  2429. 1:30:53flag for verbos that is V so that we can
  2430. 1:30:55see the output of our task I mean to say
  2431. 1:30:59uh if I open this one so we can see this
  2432. 1:31:01output like a built-in command where I'm
  2433. 1:31:03doing the EO so that's why I have added
  2434. 1:31:05a verbos parameter over there you just
  2435. 1:31:07simply need to execute
  2436. 1:31:09it okay so let's uh Analyze This output
  2437. 1:31:12task level so first we will start from
  2438. 1:31:15this particular task the name of the
  2439. 1:31:16task is environment bar at Playbook
  2440. 1:31:18level and here we are doing the Eco of
  2441. 1:31:20example so if you go to terminal once
  2442. 1:31:23again so so yeah this is the task which
  2443. 1:31:25we have executed and this is the output
  2444. 1:31:27which we are getting that is fuar and if
  2445. 1:31:30you check so yeah this is the fuar and
  2446. 1:31:32we are able to access that environment
  2447. 1:31:33variable inside that particular task and
  2448. 1:31:36because this is a global or ncble level
  2449. 1:31:40uh Playbook level variable all right now
  2450. 1:31:43coming to the next task which is
  2451. 1:31:44environment for only task level so here
  2452. 1:31:47at the task level what we have done we
  2453. 1:31:49have created this variable and the value
  2454. 1:31:51is hello world and if you go back to
  2455. 1:31:53terminal
  2456. 1:31:54uh then you will see the output that is
  2457. 1:31:56hello world so that's also correct
  2458. 1:31:58that's also valid but this third task is
  2459. 1:32:01bit interesting because here we have we
  2460. 1:32:02are accessing the example as well as the
  2461. 1:32:04previous uh this attribute uh this
  2462. 1:32:07environment variable so ideally we
  2463. 1:32:08should only get the value of example but
  2464. 1:32:11not this one so let's open the terminal
  2465. 1:32:14once again and here you can see the
  2466. 1:32:16output so here you can see the output
  2467. 1:32:18foar and that is this one this is the
  2468. 1:32:21foar and which is right actually but on
  2469. 1:32:24the other hand if you take a look then
  2470. 1:32:26the value of this variable is not
  2471. 1:32:27getting printed because that particular
  2472. 1:32:29environment variable is outside the
  2473. 1:32:31scope of that particular task so that's
  2474. 1:32:34why I have created this third task to
  2475. 1:32:36just to show you the difference between
  2476. 1:32:38the task level environment variable and
  2477. 1:32:40the Playbook level environment variables
  2478. 1:32:42all right so this is how you're just
  2479. 1:32:44going to create an environment variable
  2480. 1:32:45inside your playbook and you can access
  2481. 1:32:47those environment variable either at a
  2482. 1:32:49task level or a Playbook level well this
  2483. 1:32:52was a very small demo but this concept
  2484. 1:32:54was really important because when you
  2485. 1:32:56are going to write your anible playbook
  2486. 1:32:59for your production application then you
  2487. 1:33:01will need uh to use this environment
  2488. 1:33:03variables quite a lot and you should be
  2489. 1:33:05really careful like where you are
  2490. 1:33:06defining your environment variable
  2491. 1:33:08whether it's a task level or whether
  2492. 1:33:10it's like a Playbook level so keep in
  2493. 1:33:12mind those Concepts and try to use this
  2494. 1:33:14environment variable in those fashion
  2495. 1:33:17all right so that was all about the
  2496. 1:33:18environment variable but in the next
  2497. 1:33:19session of a anible series we are going
  2498. 1:33:21to talk about the if then and else
  2499. 1:33:23statement so stay tuned for the next
  2500. 1:33:25episode and in the upcoming weeks I'm
  2501. 1:33:27going to upload more uh similar session
  2502. 1:33:30onto the anible Playbook and anible
  2503. 1:33:32Series so stay tuned for that and if you
  2504. 1:33:35are new to this channel then you can
  2505. 1:33:37just subscribe to this channel where you
  2506. 1:33:38will find the content on terraform
  2507. 1:33:41Docker kubernetes and sible and there
  2508. 1:33:43are many sessions which I have uploaded
  2509. 1:33:45for a Helm chart also so just go and
  2510. 1:33:48check those lab session if you're new to
  2511. 1:33:50the DeVos so stay tuned for that and see
  2512. 1:33:53you into the next next session till then
  2513. 1:33:55take care and
  2514. 1:33:56bye-bye hello there this is Rahul and
  2515. 1:33:59welcome to the anible series in the
  2516. 1:34:01ninth part of this series we will be
  2517. 1:34:03talking about anible
  2518. 1:34:06conditionals now the question comes like
  2519. 1:34:08what is conditional in anible so if you
  2520. 1:34:10are familiar with any programming
  2521. 1:34:11languages then you might have used the
  2522. 1:34:13if statement for evaluating any
  2523. 1:34:15conditions similarly in anible we have a
  2524. 1:34:18conditional which will help us to
  2525. 1:34:20evaluate any condition and based on that
  2526. 1:34:22condition we will be taking the next
  2527. 1:34:23step or we will be executing the next
  2528. 1:34:25sensible instructions here onto the
  2529. 1:34:27screen you can see on the left hand side
  2530. 1:34:29it's a traditional if condition with any
  2531. 1:34:31other programming languages so where you
  2532. 1:34:33specify if and inside that you specify a
  2533. 1:34:35condition and after that you write a
  2534. 1:34:37code which you want to execute based on
  2535. 1:34:39that particular condition but in anible
  2536. 1:34:42we actually don't have a if condition
  2537. 1:34:44instead we have a when condition so
  2538. 1:34:46whenever we need to put any condition
  2539. 1:34:49then we are just going to use the when
  2540. 1:34:51conditional inside your anible playbook
  2541. 1:34:54in the beginning it might sound
  2542. 1:34:56complicated but in actual it is really
  2543. 1:34:58simple to implement a conditional using
  2544. 1:35:00a when condition so here onto the screen
  2545. 1:35:02if I scroll it down I have taken a very
  2546. 1:35:04basic example to understand this van
  2547. 1:35:06conditional so here this is my playbook
  2548. 1:35:09where I'm just trying to install an
  2549. 1:35:10Apache server onto my remote server but
  2550. 1:35:13I want to install this Apache server
  2551. 1:35:15based on one condition so here you can
  2552. 1:35:17see this is the condition which I have
  2553. 1:35:19specified using the V so here inside
  2554. 1:35:22that condition you will see a flight
  2555. 1:35:24that is install Apache flag so that's a
  2556. 1:35:26Boolean flag which I have kept and if
  2557. 1:35:28you see below over here so this is the
  2558. 1:35:31value of that particular variable and
  2559. 1:35:33here this value is bullan so based on
  2560. 1:35:36true and false I'll be able to install
  2561. 1:35:38that particular Apache so in variable
  2562. 1:35:40file if you have kept the value true
  2563. 1:35:42which you can see over here the value is
  2564. 1:35:44true so in that case if whenever I'm
  2565. 1:35:46just going to execute this particular
  2566. 1:35:48Playbook I'm talking about this Playbook
  2567. 1:35:49then it is going to install the Apache
  2568. 1:35:51server but in case if this particular
  2569. 1:35:53value this particular variable value is
  2570. 1:35:55false then in that case our uh Apache
  2571. 1:35:58server will not be installed using our
  2572. 1:36:00NC Playbook so that's the simplest
  2573. 1:36:03implementation uh which you can see over
  2574. 1:36:05here using the V condition and don't
  2575. 1:36:07worry we're just going to perform a demo
  2576. 1:36:08after this uh where we are going to
  2577. 1:36:10implement this when condition inside our
  2578. 1:36:12anible
  2579. 1:36:13Playbook all right so now you're a bit
  2580. 1:36:15familiar with the when condition and in
  2581. 1:36:17the previous example we have just seen
  2582. 1:36:19one condition inside the van conditional
  2583. 1:36:21block but now what if we can specify
  2584. 1:36:24multiple conditions inside our when
  2585. 1:36:27conditional block so here in this
  2586. 1:36:29example and onto this screen you can see
  2587. 1:36:31the example where I have taken the when
  2588. 1:36:33block and inside that V block I have a
  2589. 1:36:34specified multiple condition so this is
  2590. 1:36:37going to be my first condition and this
  2591. 1:36:38is going to be my second condition and
  2592. 1:36:40if both conditions are true then after
  2593. 1:36:43that this whole anible Playbook is going
  2594. 1:36:45to execute and it is going to install
  2595. 1:36:47anything or any task which you want to
  2596. 1:36:49perform all right so that's a one way of
  2597. 1:36:51specifying multiple condition inside
  2598. 1:36:52your van block
  2599. 1:36:54now I'm taking a one more example over
  2600. 1:36:56here I will increase the font size over
  2601. 1:36:58here so here you can use our traditional
  2602. 1:37:01and operator so here again you can
  2603. 1:37:03specify multiple condition but instead
  2604. 1:37:05of putting the condition into the next
  2605. 1:37:06line you can use the end operator and
  2606. 1:37:08specify the condition in a single line
  2607. 1:37:11so here you can see uh this is the first
  2608. 1:37:13condition which I have specified over
  2609. 1:37:14here and if I scroll it horizontally
  2610. 1:37:16then this is the end condition which you
  2611. 1:37:18can see so this is the end condition
  2612. 1:37:19which is sitting in between and this is
  2613. 1:37:22the second condition which I have
  2614. 1:37:23specified so this is a more traditional
  2615. 1:37:26way of specifying multiple condition
  2616. 1:37:28inside our when conditioner so it's up
  2617. 1:37:30to you which one you want to prefer and
  2618. 1:37:32which one you want to use I personally
  2619. 1:37:34like to prefer this previous one where
  2620. 1:37:36we have like defined each condition into
  2621. 1:37:38the next line so that it's more readable
  2622. 1:37:41and more
  2623. 1:37:43concise now moving to the next topic
  2624. 1:37:45inside our conditional so here I'm just
  2625. 1:37:47talking about putting a condition on a
  2626. 1:37:49particular value and that value can be
  2627. 1:37:52stored inside a variable so we can
  2628. 1:37:54specify conditions based on the value of
  2629. 1:37:57a particular variable so here onto the
  2630. 1:37:59screen you can see uh this is the anible
  2631. 1:38:01Playbook where we are registering a
  2632. 1:38:03variable so this is uh a register
  2633. 1:38:05keyword which is provided by anible and
  2634. 1:38:07here we are just specifying a variable
  2635. 1:38:09name that is test file content that's
  2636. 1:38:11the variable name which I have created
  2637. 1:38:13and inside that particular variable we
  2638. 1:38:15are just going to store the value of
  2639. 1:38:17this particular text file I'm just going
  2640. 1:38:19to show everything into the demo but
  2641. 1:38:21this is the text file uh which is
  2642. 1:38:23present onto my remote server and
  2643. 1:38:25whatever content present inside the text
  2644. 1:38:26file I'm just going to store inside this
  2645. 1:38:28particular variable so that's the first
  2646. 1:38:31part of anible Playbook and what I'm
  2647. 1:38:33just going to do I'm just going to put
  2648. 1:38:34the condition on that particular
  2649. 1:38:36variable so here in the next anible
  2650. 1:38:39Playbook task you will see I'm putting a
  2651. 1:38:41v block over here so if you can see over
  2652. 1:38:43here this is the V and here I'm just
  2653. 1:38:45specifying the condition on that
  2654. 1:38:47particular variable so here you can see
  2655. 1:38:49test file contain STD out you need to uh
  2656. 1:38:52fet that particular value inside from
  2657. 1:38:55inside the variable so that's why I'm
  2658. 1:38:56just using STD out that's a standard
  2659. 1:38:58output and after that I'm just putting a
  2660. 1:39:00fine condition because I'm expecting a
  2661. 1:39:03high content I have just uh it is just a
  2662. 1:39:05manual text which I have put inside the
  2663. 1:39:07text file so I'm expecting it will
  2664. 1:39:08return high so I'm just trying to find
  2665. 1:39:10that particular content and if this
  2666. 1:39:12particular condition satisfied then I'll
  2667. 1:39:14say yeah just execute this particular
  2668. 1:39:17task so this is the condition which I
  2669. 1:39:19have put over here so when this
  2670. 1:39:21particular condition satisfied then I'm
  2671. 1:39:22just going to print out the output of
  2672. 1:39:24that particular variable so that's how
  2673. 1:39:27you're just going to uh like register a
  2674. 1:39:29variable assign some value to it and
  2675. 1:39:31later on you're just going to evaluate
  2676. 1:39:33that particular value based on the when
  2677. 1:39:35conditional so this is how you can play
  2678. 1:39:37around with the variables
  2679. 1:39:39also all right moving to the next Topic
  2680. 1:39:42in conditional so now I'm going to talk
  2681. 1:39:44about the loops and you might be
  2682. 1:39:45familiar with the for Loop or for each
  2683. 1:39:47Loop in any other programming languages
  2684. 1:39:49for example python Java go or any
  2685. 1:39:52programming languages they must have
  2686. 1:39:54some kind of a looping logic implemented
  2687. 1:39:57inside those programming languages but
  2688. 1:39:59here in anible we can also use the
  2689. 1:40:00looping and here I have just taken a
  2690. 1:40:02very simple example where I have created
  2691. 1:40:05uh like a condition uh based on the
  2692. 1:40:07value of that particular uh list
  2693. 1:40:09actually so here I'm just first of all
  2694. 1:40:11going to define the loop that's the
  2695. 1:40:13keyword from anible and here I'm just
  2696. 1:40:15going to specify the array of numbers
  2697. 1:40:18and based on certain condition I'm just
  2698. 1:40:20going to like print uh the value of
  2699. 1:40:22those uh variables which is present
  2700. 1:40:25inside my array but the condition is I'm
  2701. 1:40:27just going to print the value which are
  2702. 1:40:29only greater than five so here I have a
  2703. 1:40:32specified that condition over here so
  2704. 1:40:34when this Loop is getting executed then
  2705. 1:40:36this when condition will be evaluated
  2706. 1:40:39I'm talking about this one condition and
  2707. 1:40:41when this condition is evaluated then we
  2708. 1:40:43are just going to evaluate whether that
  2709. 1:40:44value is lesser than five or greater
  2710. 1:40:46than five if it's greater than five then
  2711. 1:40:48we are just going to do the print of
  2712. 1:40:50that particular value so this is how you
  2713. 1:40:52also can use use the when conditional
  2714. 1:40:54inside your
  2715. 1:40:56loops and the last topic before the demo
  2716. 1:40:59is anible facts so we can use the
  2717. 1:41:03condition the van condition on anible
  2718. 1:41:05facts also so anible facts are something
  2719. 1:41:07which is like inbuilt so if you're
  2720. 1:41:09trying to run an anible Playbook on a
  2721. 1:41:11remote machine then anible facts will
  2722. 1:41:14always hold the value of that particular
  2723. 1:41:16remote machine and what does it mean by
  2724. 1:41:18value I'm not referring to a single
  2725. 1:41:19value but I'm referring here to the
  2726. 1:41:21multiple values so it might contain what
  2727. 1:41:23the remote IP what's the operating
  2728. 1:41:25system whether it's a sento whether it's
  2729. 1:41:27a daan and what's the version it is
  2730. 1:41:29running what's the CPU type what's the
  2731. 1:41:31chip type so all these information which
  2732. 1:41:33is like a metadata about that particular
  2733. 1:41:35machine will be stored automatically
  2734. 1:41:37inside the anible facts and using those
  2735. 1:41:40in insensible facts which you can see I
  2736. 1:41:42have just taken one example of this
  2737. 1:41:43anible facts from the anible
  2738. 1:41:45documentation so these are the facts you
  2739. 1:41:47can capture for that particular remote
  2740. 1:41:49machine and these uh particular
  2741. 1:41:52variables like all IP addresses and uh
  2742. 1:41:55also there are like ncble app armor so
  2743. 1:41:58these are the facts which is readily
  2744. 1:42:00available to you so you can put the
  2745. 1:42:02condition on these particular anible
  2746. 1:42:04facts also so here I have taken one
  2747. 1:42:06example which you can see over here so
  2748. 1:42:08here I I have just specified the V
  2749. 1:42:10condition but this V condition is
  2750. 1:42:11running on the anible facts this is the
  2751. 1:42:14keyword and what anible facts I just
  2752. 1:42:16wanted to evaluate so I just want to
  2753. 1:42:18evaluate the OS family so what's the OS
  2754. 1:42:20family of the remote machine so that
  2755. 1:42:23that's the when condition I'm just going
  2756. 1:42:24to evaluate since I'm running the uban 2
  2757. 1:42:26and which is a devian base so I just I'm
  2758. 1:42:28expecting the value is to be devian so
  2759. 1:42:32these conditionals you can put onto the
  2760. 1:42:34anible facts also so this is just a One
  2761. 1:42:37More Concept which is left inside the
  2762. 1:42:39conditional which is I just wanted to
  2763. 1:42:40show you before the
  2764. 1:42:42demo all right so moving to my intellig
  2765. 1:42:45where I have written my anible playbook
  2766. 1:42:47and on the left hand side you will see
  2767. 1:42:48this is the project which I have created
  2768. 1:42:50onto my GitHub repository I'll put the
  2769. 1:42:52link of this particular GitHub
  2770. 1:42:53repository into the description section
  2771. 1:42:55so feel free to clone that particular
  2772. 1:42:57repository so here this is uh the
  2773. 1:43:00project structure and here I have
  2774. 1:43:01created a part nine and inside that you
  2775. 1:43:03will find a task and variables file and
  2776. 1:43:06also the main Playbook and after that
  2777. 1:43:08you will find a read me file so you can
  2778. 1:43:10just simply copy this anible Playbook
  2779. 1:43:12command from here to run this particular
  2780. 1:43:14anal Playbook but in the host file you
  2781. 1:43:16need to uh update the remote host IP so
  2782. 1:43:20here I'm just using my AWS ec2 instance
  2783. 1:43:23which is running onto the uh AWS Cloud
  2784. 1:43:26so that's why I'm using it over here but
  2785. 1:43:28instead you can use your own remote
  2786. 1:43:30machine all right so that's all about
  2787. 1:43:32the practicalities of this particular
  2788. 1:43:35project but let's go back to the uh
  2789. 1:43:37actual code where I have specified these
  2790. 1:43:40conditionals so here this is the first
  2791. 1:43:43block where I have specified install
  2792. 1:43:44Apache web server based on the condition
  2793. 1:43:47that is install Apache flag and that's a
  2794. 1:43:49Boolean variable so let's check the
  2795. 1:43:51value of that particular V buan variable
  2796. 1:43:53and that is true so that means if I'm
  2797. 1:43:56going to execute this particular anible
  2798. 1:43:58Playbook then it is going to install the
  2799. 1:43:59Apache server onto my remote machine so
  2800. 1:44:02that's the first use case what I I'm
  2801. 1:44:05going to do I'm just going to remove
  2802. 1:44:06rest of the details so that we only run
  2803. 1:44:09the required one I'm just going to save
  2804. 1:44:11this thing go to the readme file over
  2805. 1:44:13here copy this anible Playbook command
  2806. 1:44:16open the
  2807. 1:44:18terminal and here into the terminal uh
  2808. 1:44:20you can just simply paste that
  2809. 1:44:21particular command for executing your an
  2810. 1:44:24label uh let me check the folder where I
  2811. 1:44:27am in so I need to switch to see uh part
  2812. 1:44:30n I'll clear the screen and just check
  2813. 1:44:33yeah I'm inside my directory that is
  2814. 1:44:35part mine and after that you can just
  2815. 1:44:37simply run that command this is the
  2816. 1:44:39command which I'm just going to execute
  2817. 1:44:41simply execute it all right so here you
  2818. 1:44:43can see uh that it has successfully
  2819. 1:44:46executed the install Apache web server
  2820. 1:44:49so that means based on that particular
  2821. 1:44:51condition which is true right now it is
  2822. 1:44:52able B to install the Apache but I'm
  2823. 1:44:55just going to do one more thing uh what
  2824. 1:44:56I'm just going to do I'm just going to
  2825. 1:44:58update the value and set it to false so
  2826. 1:45:03once we set anything or this particular
  2827. 1:45:05condition to false then it is going to
  2828. 1:45:06skip that particular installation step
  2829. 1:45:09so I'll just go back to terminal once
  2830. 1:45:11again and I'm just going to re-execute
  2831. 1:45:13although we have installed Apache but
  2832. 1:45:15our main intention is not to install
  2833. 1:45:17Apache button Ste we just wanted to
  2834. 1:45:18check the condition so here you can see
  2835. 1:45:20it has skipped that particular step so
  2836. 1:45:23what does it mean so that means that
  2837. 1:45:24based on that particular condition it is
  2838. 1:45:26evaluating whether it whether it has to
  2839. 1:45:29execute that tensible task or not so in
  2840. 1:45:31that case when we have set the value to
  2841. 1:45:33false it has just skipped that
  2842. 1:45:35particular task now in the next example
  2843. 1:45:37we are just going to evaluate multiple
  2844. 1:45:39condition based on the anible facts so
  2845. 1:45:42here onto the screen you can see this is
  2846. 1:45:43the when condition which I have
  2847. 1:45:45specified but inside that V condition I
  2848. 1:45:47have a specified couple of more
  2849. 1:45:48condition and these conditions are just
  2850. 1:45:51simply checking the anible facts so the
  2851. 1:45:53facts where I'm talking about is the OS
  2852. 1:45:55family so what kind of os family the
  2853. 1:45:57remote machine belongs to and since it's
  2854. 1:45:59UB to best so that's a Dean so that's
  2855. 1:46:01the first check secondly what's the
  2856. 1:46:03distribution major version so what's the
  2857. 1:46:05OS version of that Linux machine so
  2858. 1:46:07which is 20 so that I already know it so
  2859. 1:46:10that's why I have put this particular
  2860. 1:46:11condition so again let's go back to
  2861. 1:46:13terminal over here I'm just going to
  2862. 1:46:15clear the previous
  2863. 1:46:16output and I'm just going to Simply run
  2864. 1:46:18the N Playbook and here you can see uh
  2865. 1:46:22since the previous value we have set for
  2866. 1:46:23install Apache to false that's why it
  2867. 1:46:25has been skied but this task combined
  2868. 1:46:28condition using anel has executed
  2869. 1:46:30successfully and if we check over here
  2870. 1:46:32then what we are doing over here when
  2871. 1:46:34this particular both the conditions are
  2872. 1:46:36passed then we are just printing the
  2873. 1:46:38kernel version into the console so here
  2874. 1:46:41just go back to terminal and check so
  2875. 1:46:43here you can see the anible kernel
  2876. 1:46:45version which is 40 Ubuntu SMP and the
  2877. 1:46:48time St so which has evaluated that
  2878. 1:46:51particular condition has evalu ated that
  2879. 1:46:53condition properly and our both the
  2880. 1:46:55facts anible facts are true and we have
  2881. 1:46:57got the output over here okay moving
  2882. 1:46:59back to my anible playbook so here I
  2883. 1:47:01have specified the same condition using
  2884. 1:47:03the and condition over here so you can
  2885. 1:47:05see again the anle facts I'm checking
  2886. 1:47:08over here are same I'm just still
  2887. 1:47:10checking the Debian as well as I'm just
  2888. 1:47:12checking the version which is what is
  2889. 1:47:14the major version and that has to be
  2890. 1:47:15greater than 20 so that's the only
  2891. 1:47:17change which I have did from the
  2892. 1:47:19previous condition where I was checking
  2893. 1:47:20for exact 20 version but here I'm just
  2894. 1:47:22checking a version which is greater than
  2895. 1:47:24or equal to 20 but rest of the
  2896. 1:47:26conditions are same so I just wanted to
  2897. 1:47:28demonstrate you that's why I have put
  2898. 1:47:29this particular task over here so onto
  2899. 1:47:32the terminal if you go back I'll clear
  2900. 1:47:34the screen once again and you can just
  2901. 1:47:36simply run the N playable and here you
  2902. 1:47:39can see the setting complex condition
  2903. 1:47:40that was my task name and we can verify
  2904. 1:47:42it over here so setting complex
  2905. 1:47:44condition and here we are having two
  2906. 1:47:45condition this is the first one and this
  2907. 1:47:47is the second one and onto the terminal
  2908. 1:47:50you will see the output the anible
  2909. 1:47:52kernel version which which is 40 so
  2910. 1:47:54that's how you can put multiple
  2911. 1:47:55conditions inside your anible task
  2912. 1:47:57within your anible playbook all right
  2913. 1:47:59now moving to the next example where I
  2914. 1:48:00have shown or where I have already
  2915. 1:48:02explained like how to register a
  2916. 1:48:03variable and then assign a value to that
  2917. 1:48:06particular variable and then evaluate
  2918. 1:48:08that particular variable so here I'm
  2919. 1:48:10just first of all going to register a
  2920. 1:48:11variable with the name test file content
  2921. 1:48:14and after that I'm just going to
  2922. 1:48:15evaluate the value of that particular
  2923. 1:48:17variable and the value I'm expecting
  2924. 1:48:19over here is just a two character which
  2925. 1:48:21is high so I'm expecting a file to be
  2926. 1:48:24present at that particular location so
  2927. 1:48:26I'm just going to go to my terminal and
  2928. 1:48:28this is my remote machine I'll just
  2929. 1:48:30clear the screen just check the path
  2930. 1:48:32that I'm under home/ to just do the ls
  2931. 1:48:36to verify the file there is a file test
  2932. 1:48:37file.txt and you can just do the cat to
  2933. 1:48:40verify the content and here you can see
  2934. 1:48:42the content of file is just a simple two
  2935. 1:48:45character which is high so I'm just
  2936. 1:48:47going to fetch this particular value of
  2937. 1:48:49a file inside the variable and then I'm
  2938. 1:48:51just going to evaluate the condition so
  2939. 1:48:53this is the command uh to do the cat and
  2940. 1:48:56it will register into this variable and
  2941. 1:48:57then we are just going to do the
  2942. 1:48:59standard out and then compare the value
  2943. 1:49:02all right so let's go back and here
  2944. 1:49:04after the comparing the value this will
  2945. 1:49:06debug and print the value of that
  2946. 1:49:08particular variable so that we know that
  2947. 1:49:10condition has been evaluated so let's go
  2948. 1:49:13back to terminal and uh I'll clear the
  2949. 1:49:15screen over here and simply execute the
  2950. 1:49:18play and here you can see first of all
  2951. 1:49:20it has registered the variable so it has
  2952. 1:49:22fatch the value of that particular file
  2953. 1:49:25and after that it has evaluated that
  2954. 1:49:26condition and print the value of that
  2955. 1:49:28particular variable so which you can see
  2956. 1:49:30which is high so here uh this is the
  2957. 1:49:33output which we have just verified all
  2958. 1:49:35right now moving to the next example
  2959. 1:49:37where I have shown the loop so here I
  2960. 1:49:39have a specified the array so where I'm
  2961. 1:49:41just going to Loop so that array
  2962. 1:49:42contains the value 0 2 4 6 8 and 10 but
  2963. 1:49:45the condition which I'm putting over
  2964. 1:49:47here is item should be greater than five
  2965. 1:49:49and once the value is greater than five
  2966. 1:49:50then I'm just going to print the value
  2967. 1:49:52of that particular item so that's the
  2968. 1:49:54simplest uh like a for Loop or The Loop
  2969. 1:49:57which I have implemented over here so
  2970. 1:49:58I'm just going to head over to terminal
  2971. 1:50:00I'm just going to clear the screen and
  2972. 1:50:02run the
  2973. 1:50:03Playbook and here you can see the output
  2974. 1:50:05onto the terminal but if you take a look
  2975. 1:50:08carefully then you need to check which
  2976. 1:50:10part has been skipped and which part has
  2977. 1:50:12been changed so this skipped part which
  2978. 1:50:15means we we are we are not printing 0 2
  2979. 1:50:18and four I mean these values are script
  2980. 1:50:20because those were lesser than five but
  2981. 1:50:22the values which are greater than five
  2982. 1:50:24has been uh printed over here with a
  2983. 1:50:26changed uh like highlighted so these are
  2984. 1:50:29the values which has been entertained
  2985. 1:50:31and which has been printed using that
  2986. 1:50:33for Loop so that's how you're just going
  2987. 1:50:35to iterate over a loop using the
  2988. 1:50:37conditional and moving to the last part
  2989. 1:50:39where I was talking about the anible
  2990. 1:50:41facts and you can put multiple anible
  2991. 1:50:43facts inside your when conditioner so
  2992. 1:50:45here I have just taken a fact uh the
  2993. 1:50:47anible fact is a keyword over here and
  2994. 1:50:49the fact I'm verifying is the operating
  2995. 1:50:51system family and I'm expecting value to
  2996. 1:50:53be Debian if it's Debian then I'm just
  2997. 1:50:55going to print the distribution name of
  2998. 1:50:57that particular anmol F so go to
  2999. 1:51:00terminal clear the screen uh screen is
  3000. 1:51:02already cleared so I'm just going to
  3001. 1:51:04execute the
  3002. 1:51:06Playbook and here you can see uh anible
  3003. 1:51:08distribution which is one two so that's
  3004. 1:51:10how I'm just going to evaluate uh my
  3005. 1:51:13anible facts and after evaluating inside
  3006. 1:51:15the van condition I'm just going to
  3007. 1:51:16print the web all right so that
  3008. 1:51:18concludes our ninth lab session on
  3009. 1:51:20anible and till now we have covered
  3010. 1:51:22fourth chapter which you can see over
  3011. 1:51:23here from the content page and in the
  3012. 1:51:25next chapter we'll be talking about the
  3013. 1:51:27roles and the task associated with your
  3014. 1:51:29Anvil Playbook and in that session we'll
  3015. 1:51:32be talking about how to import the roles
  3016. 1:51:34how to import the different task inside
  3017. 1:51:36your anible playbook so stay tuned for
  3018. 1:51:38that and if you interested into the
  3019. 1:51:40similar content on devops where I talk
  3020. 1:51:42about terraform kubernetes stalker
  3021. 1:51:44containers and Helm chart then please
  3022. 1:51:46consider subscribing to this channel
  3023. 1:51:47because there are similar session I have
  3024. 1:51:49planned in the future and upcoming
  3025. 1:51:51months which you will see onto this
  3026. 1:51:52channel so till then take care and
  3027. 1:51:56bye-bye hello there this is Rahul and
  3028. 1:51:58welcome to the sensible series and in
  3029. 1:52:00this 10th part we will be taking a look
  3030. 1:52:02onto the task and the
  3031. 1:52:05roles the idea of this session is to
  3032. 1:52:07understand what are roles and how to
  3033. 1:52:08create multiple task inside your anible
  3034. 1:52:10playbook so in this session we'll first
  3035. 1:52:12try to look and understand what is Task
  3036. 1:52:14and the rules and after that we are just
  3037. 1:52:16going to perform a demo to understand
  3038. 1:52:18both task and the
  3039. 1:52:20roles all right so to begin with it's
  3040. 1:52:23really important for us to understand
  3041. 1:52:25the structure of our roles and the task
  3042. 1:52:27so here onto the screen if you'll see
  3043. 1:52:29this is the screenshot which I have
  3044. 1:52:30taken from my projects and into this
  3045. 1:52:32screenshot you will see there is a roles
  3046. 1:52:34so this is the roles which I have
  3047. 1:52:35created this is the standard roles
  3048. 1:52:37directory where we are going to define
  3049. 1:52:38the roles and here I have created couple
  3050. 1:52:40of roles so this is the first one and
  3051. 1:52:42this is the second one so the name of
  3052. 1:52:44the first role is custom role because I
  3053. 1:52:45just wanted to create my own custom Ro
  3054. 1:52:47but here in the second role if you'll
  3055. 1:52:49see there is a unique name that is
  3056. 1:52:51install Apache so that dictates like the
  3057. 1:52:53second role is going to install the
  3058. 1:52:55Apache so whenever you're working with
  3059. 1:52:57an anible Playbook and you need to
  3060. 1:52:58create a multiple task then what you're
  3061. 1:53:00going to do first of all you're just
  3062. 1:53:01going to go inside your roles directory
  3063. 1:53:04and inside that you're just going to
  3064. 1:53:05create the roles directories inside
  3065. 1:53:08those now once you created those roles
  3066. 1:53:11inside your roles directories now it's
  3067. 1:53:13time for you to include those Ro inside
  3068. 1:53:15your main anible Playbook so here the
  3069. 1:53:17main anible Playbook is this one which
  3070. 1:53:19is anible import roles Playbook yml so
  3071. 1:53:22that is going to be my main Playbook so
  3072. 1:53:24you need to include those roles inside
  3073. 1:53:26that main Playbook so once you execute
  3074. 1:53:28that particular main Playbook then it is
  3075. 1:53:29going to execute those roles also so if
  3076. 1:53:32you scroll down further then I have
  3077. 1:53:34taken one more screenshot that is from
  3078. 1:53:36my main anible Playbook so here you will
  3079. 1:53:38see this is the first role which I have
  3080. 1:53:40included and here this is the second
  3081. 1:53:42role which I have included so once I'll
  3082. 1:53:44execute this my main Playbook then it is
  3083. 1:53:46going to execute first the custom role
  3084. 1:53:48and then it is going to execute my
  3085. 1:53:49second role which is install
  3086. 1:53:51Apache
  3087. 1:53:53all right so now we have taken a look
  3088. 1:53:54onto the project structure of our roles
  3089. 1:53:56and how to include those role inside
  3090. 1:53:58your main anible
  3091. 1:54:00Playbook let's talk about the task and
  3092. 1:54:02how to create those task within those
  3093. 1:54:04roles so if you take a look over here
  3094. 1:54:06into the custom Ro and the install
  3095. 1:54:07Apache role we have created a task
  3096. 1:54:09directory so that's a standard practice
  3097. 1:54:11which you need to follow while creating
  3098. 1:54:12the task so if you expand that
  3099. 1:54:14particular directory the task directory
  3100. 1:54:15then you will find a main. yml so that's
  3101. 1:54:18again you need to follow this standard
  3102. 1:54:19practice of creating a main. yml within
  3103. 1:54:21that particular task because in that
  3104. 1:54:23main. yml you're just going to define
  3105. 1:54:25the task for that particular role so
  3106. 1:54:28here you will find the main. yml and
  3107. 1:54:29also for install Apache you will also
  3108. 1:54:31find a main. yml so those are the
  3109. 1:54:33standard practice which you need to keep
  3110. 1:54:34in mind now let's open the main. yml of
  3111. 1:54:36one of the role and see what's present
  3112. 1:54:38inside those so let's take a very simple
  3113. 1:54:40one that is install Apache Ro and there
  3114. 1:54:42is one main. yml present inside it so if
  3115. 1:54:44you're going to open that particular
  3116. 1:54:46main. yml then you will find the small
  3117. 1:54:47small task that is first task is to
  3118. 1:54:49install the Apache and the second task
  3119. 1:54:51is to start the Apache server so that's
  3120. 1:54:53the task which you have defined into
  3121. 1:54:55that particular role and these
  3122. 1:54:57particular task are associated with this
  3123. 1:54:59particular install Apache role so once
  3124. 1:55:01you include that particular role over
  3125. 1:55:03here that is install Apache then it is
  3126. 1:55:05going to what it's going to do it is
  3127. 1:55:07first going to install the Apache and
  3128. 1:55:08then it is going to start the Apache
  3129. 1:55:12service let's take one more use case
  3130. 1:55:14where we are going to create a subtask
  3131. 1:55:16within the task so here in the custom Ro
  3132. 1:55:18what I have done I have created a main.
  3133. 1:55:20yml but that main. yml is still
  3134. 1:55:22dependent on the subtasks so here there
  3135. 1:55:25are a couple of tasks which I have
  3136. 1:55:26defined that is messages. yml and that
  3137. 1:55:28is packages. yml so these are the
  3138. 1:55:30further subtask which I want to execute
  3139. 1:55:32when I'm executing this particular
  3140. 1:55:34anible Playbook so inside the main. yml
  3141. 1:55:37you first of all you will see I have
  3142. 1:55:38included or I have imported the package.
  3143. 1:55:41yml that is package task and after that
  3144. 1:55:43I have also imported the message. yml
  3145. 1:55:45that is my message task and after that
  3146. 1:55:48I'm just writing one my task which is to
  3147. 1:55:51start the Eng genic Serv
  3148. 1:55:52so let's take a look into the packages.
  3149. 1:55:54yml first of all so if you open this one
  3150. 1:55:56then what it's going to do it is just
  3151. 1:55:57going to install some packages it is
  3152. 1:55:59going to install enginex it is going to
  3153. 1:56:01install G and it is going to install
  3154. 1:56:03curve so that's the package. yml and it
  3155. 1:56:05is a subtask present within the custom
  3156. 1:56:08role and after that we need to include
  3157. 1:56:10that into our main. yml all right so
  3158. 1:56:12that's our packages. yml the second
  3159. 1:56:14thing is the message. yml which I have
  3160. 1:56:16already included or imported as a task
  3161. 1:56:18so here what I'm doing simply I'm just
  3162. 1:56:20copying uh the content of our uh like a
  3163. 1:56:23HTML file which is present for Engen
  3164. 1:56:26server and after that I'm just including
  3165. 1:56:28it over here into the message. yml and
  3166. 1:56:31finally we are just in restarting or
  3167. 1:56:33starting our engine service onto my UB
  3168. 1:56:35Tu machine so that's how you're just
  3169. 1:56:37going to create a multiple subtask
  3170. 1:56:39within that uh particular custom role
  3171. 1:56:41and it can depend uh of course the name
  3172. 1:56:43can be differ in your case but once you
  3173. 1:56:46create those role then in that role you
  3174. 1:56:47can create a subtask also and you can
  3175. 1:56:49import those task within your main
  3176. 1:56:53yml all right let's run this Playbook to
  3177. 1:56:55verify the task and the roles which we
  3178. 1:56:57have created so what you need to do you
  3179. 1:56:59just need to go to the readme file and
  3180. 1:57:00here you will find the Run Playbook
  3181. 1:57:02instruction so you simply need to copy
  3182. 1:57:03this command so it's basically doing uh
  3183. 1:57:05it's just running this Nel import Ro
  3184. 1:57:08Playbook and from the host and the host
  3185. 1:57:09I have already defined over here in the
  3186. 1:57:11ncble import Ro and the host so that's
  3187. 1:57:13where you will find the host definition
  3188. 1:57:15okay so I'm just going to open the
  3189. 1:57:17terminal over here and I'm just going to
  3190. 1:57:18P the command and hit enter so it should
  3191. 1:57:20execute and it should include all those
  3192. 1:57:22roles which we have created and it will
  3193. 1:57:24execute all those tasks so let's see
  3194. 1:57:26over here okay so here you can see uh if
  3195. 1:57:29you go one by one so here we have first
  3196. 1:57:31of all installed the package from the
  3197. 1:57:33custom role so that's the first thing
  3198. 1:57:34which we have did from the custom Ro we
  3199. 1:57:36have set the message file which we have
  3200. 1:57:37also seen then after that we are just
  3201. 1:57:39restarting the engine server so that's
  3202. 1:57:41where uh the three task which has been
  3203. 1:57:43performed within the custom Ro now
  3204. 1:57:45coming to uh the second part where we
  3205. 1:57:47are just going to install the Apache
  3206. 1:57:48which is our second role so here first
  3207. 1:57:51of all we are just installing the aache
  3208. 1:57:52then we are updating the configuration
  3209. 1:57:54of Apache and then finally we are
  3210. 1:57:55starting the Apache so that's how you're
  3211. 1:57:57just going to execute your anible
  3212. 1:57:59playbook which is includes multiple
  3213. 1:58:01roles and in those roles we can have
  3214. 1:58:02multiple tasks so that was all about the
  3215. 1:58:04roles and task in anible and till now we
  3216. 1:58:07have completed five chapters and uh in
  3217. 1:58:09the next chapter we'll be talking about
  3218. 1:58:10the templating in anible so where we
  3219. 1:58:12will be covering the topics like a
  3220. 1:58:14ginger templates I'll be taking a one
  3221. 1:58:15example of a ginger template and it will
  3222. 1:58:17help you to understand like how you can
  3223. 1:58:19create the ginger template so stay tuned
  3224. 1:58:21for that and if you're interested into
  3225. 1:58:22the similar content on a devops then
  3226. 1:58:24please considering subscribing to this
  3227. 1:58:25channel so see you into the next session
  3228. 1:58:27of anible and devops till then take care
  3229. 1:58:28and
  3230. 1:58:30bye-bye the objective of this session is
  3231. 1:58:32to understand what is Ginger 2 template
  3232. 1:58:34in anible and how to use the Ginger 2
  3233. 1:58:36template for your anible
  3234. 1:58:39playbooks before we jump to the demo
  3235. 1:58:41let's try to understand like what is
  3236. 1:58:43Ginger 2 template so as you can see onto
  3237. 1:58:45the screen I have listed two benefits of
  3238. 1:58:47ginger 2 template the first one is the
  3239. 1:58:49dynamic configuration and the second one
  3240. 1:58:51is the Dynamic script so whenever you
  3241. 1:58:53want to use the dynamic configuration or
  3242. 1:58:56dynamic script then you should rely on
  3243. 1:58:58the Ginger 2 template I know it sounds
  3244. 1:59:00complicated but the next example which
  3245. 1:59:02I'm just going to take it is going to
  3246. 1:59:04explain the Ginger 2 template in a very
  3247. 1:59:06simple
  3248. 1:59:07manner all right so then let's start
  3249. 1:59:09with like how you can create a ginger to
  3250. 1:59:11template so onto the screen you can see
  3251. 1:59:13I have created my Ginger 2 template with
  3252. 1:59:15the name like my config do J2 so any
  3253. 1:59:19ginger2 template which you are creating
  3254. 1:59:21inside your ible project that should end
  3255. 1:59:23with the extension file name that is J2
  3256. 1:59:27that is Ginger 2 template and you can
  3257. 1:59:29Define any name for your Ginger 2
  3258. 1:59:31template so here I have kept the name as
  3259. 1:59:33a my config but in your case you can
  3260. 1:59:35keep any name of your
  3261. 1:59:37choice now once you have defined your
  3262. 1:59:39Ginger 2 templates then I'm assuming
  3263. 1:59:41your Ginger 2 templates is empty but
  3264. 1:59:44here I have just taken a one screenshot
  3265. 1:59:45and don't worry we are just going to
  3266. 1:59:47take a demo and where I'm going to show
  3267. 1:59:48you the complete configuration also but
  3268. 1:59:51here onto the the screen if you will see
  3269. 1:59:53this is the configuration of my one of
  3270. 1:59:55the HTTP server and This Server here I'm
  3271. 1:59:57just trying to put the dynamic value for
  3272. 2:00:00Server Port which you can see over here
  3273. 2:00:02which I have already highlighted so
  3274. 2:00:04whenever you're working with the Ginger
  3275. 2:00:062 template then you need to provide a
  3276. 2:00:08interpolation so here the interpolation
  3277. 2:00:10starts with the double curly braces on
  3278. 2:00:12the left side and double curly braces on
  3279. 2:00:15the right side and between those you
  3280. 2:00:17need to put the variable which is a
  3281. 2:00:19dynamic value which you will be
  3282. 2:00:21providing in from your anible playbook
  3283. 2:00:24so that's the first rule for using the
  3284. 2:00:27Ginger 2
  3285. 2:00:28template all right so now you know like
  3286. 2:00:30how to create your Ginger 2 template
  3287. 2:00:32with the J2 extension and how to create
  3288. 2:00:34your interpolation and assign some
  3289. 2:00:37variable inside those interpolation the
  3290. 2:00:39next thing which I'm just going to talk
  3291. 2:00:41about is how to call your gingu template
  3292. 2:00:43inside your anible playbook and how how
  3293. 2:00:46to pass the variable value which you are
  3294. 2:00:48using inside your interpolation so the
  3295. 2:00:51first thing which we are going to take a
  3296. 2:00:52look is like how to call your Ginger 2
  3297. 2:00:54template so as you can see this is the
  3298. 2:00:56screenshot which I have taken and here
  3299. 2:00:58first of all you need to use the keyword
  3300. 2:01:00which is template so that anible
  3301. 2:01:03Playbook know that you are just going to
  3302. 2:01:05use the Ginger 2 template after that you
  3303. 2:01:08need to specify the file name along with
  3304. 2:01:10the path since this sensible Playbook
  3305. 2:01:13and ginger to template are presented the
  3306. 2:01:15same directory that's why I have just
  3307. 2:01:17specified the name of that Ginger 2
  3308. 2:01:19template because that's present in the
  3309. 2:01:21same directory third thing which is
  3310. 2:01:24really important is like you need to
  3311. 2:01:26pass the value to that particular
  3312. 2:01:28variable and in our case the variable is
  3313. 2:01:30server Port so here you need to use the
  3314. 2:01:33vars keyword inside your anible playbook
  3315. 2:01:35so that it knows that you are just
  3316. 2:01:37passing the variable and after that you
  3317. 2:01:39need to assign the value whatever you
  3318. 2:01:41want to assign to it so these These are
  3319. 2:01:44the key principles when you're are using
  3320. 2:01:46the gingu template so first of all you
  3321. 2:01:48need to use the template keyword after
  3322. 2:01:50that you need to specify the ninja to
  3323. 2:01:52template file name along with the
  3324. 2:01:54correct path and after that you need to
  3325. 2:01:56use the wars keyword and then you can
  3326. 2:01:58just specify the variable value which
  3327. 2:02:00you are trying to use inside your
  3328. 2:02:02interpolation so in that case this is
  3329. 2:02:04our server uncore port and that is the
  3330. 2:02:07value which is
  3331. 2:02:09480 let's start with the demo and first
  3332. 2:02:11of all we are just going to take a look
  3333. 2:02:13onto the project structure and where we
  3334. 2:02:15have defined our Ginger 2 template so
  3335. 2:02:18here onto the screen you can see this is
  3336. 2:02:19the part 11 anible Ginger 2 template
  3337. 2:02:22that's the directory and here I have
  3338. 2:02:24created a roles directory and don't
  3339. 2:02:26worry this whole project is available
  3340. 2:02:28onto my GitHub repository so you can
  3341. 2:02:30find the link of my GitHub repository
  3342. 2:02:32into the description section and here
  3343. 2:02:35into the roles directory I have created
  3344. 2:02:36one rule that is install Light httpd
  3345. 2:02:39that's the one more server it's simple
  3346. 2:02:41HTTP server and here inside the task I
  3347. 2:02:45have created a main.yml but along with
  3348. 2:02:47that I have a my config do J2 that's my
  3349. 2:02:50Ginger 2 template and and remember I'm
  3350. 2:02:52just going to use this gingu template
  3351. 2:02:54inside the main. yml that's why I have
  3352. 2:02:56kept it over there but in case if you
  3353. 2:02:58have kept that particular Ginger 2
  3354. 2:03:00template in some other directory then
  3355. 2:03:02you need to put the correct path when
  3356. 2:03:04using your Ginger 2 template all right
  3357. 2:03:07that's that's something related to how
  3358. 2:03:09to include your Ginger 2 template but if
  3359. 2:03:11you take a look onto This Ginger 2
  3360. 2:03:13template then here at line number 14
  3361. 2:03:15this is the uh variable value which I'm
  3362. 2:03:18passing dynamically so here onto the
  3363. 2:03:21screen you can see this is the
  3364. 2:03:22interpolation syntax which is available
  3365. 2:03:24here on both left hand side and right
  3366. 2:03:26hand side and here is the value of that
  3367. 2:03:28particular variable which we will be
  3368. 2:03:30passing when we are running the anible
  3369. 2:03:31label let's take a look onto the main.
  3370. 2:03:34yml and how to include our gingu
  3371. 2:03:36template so just double click onto this
  3372. 2:03:38main. yml and here you can see at line
  3373. 2:03:41number 11 that's the source directory
  3374. 2:03:43and where I'm just going to specify my
  3375. 2:03:45ginger2 template file name so here I
  3376. 2:03:48have a specified that is my config do J2
  3377. 2:03:51and remember always keep this Source
  3378. 2:03:53directory inside the template tag so
  3379. 2:03:56that's the key thing when you when you
  3380. 2:03:58are using the Ginger 2 template all
  3381. 2:04:00right now the next thing which you need
  3382. 2:04:02to do over here is to define the vars
  3383. 2:04:04and in the vars you need to specify what
  3384. 2:04:07variable you're passing inside your
  3385. 2:04:09gingu template so here I'm specifying
  3386. 2:04:11server undor port and the value is ET
  3387. 2:04:14and which you can see over here into the
  3388. 2:04:15gingu template which is server P so
  3389. 2:04:18that's how I'm just going to include my
  3390. 2:04:21Ginger temp template and I'm just going
  3391. 2:04:22to assign some value or passing some
  3392. 2:04:24value to the server Cod variable all
  3393. 2:04:27right so that's all about the ginger to
  3394. 2:04:29template and how to include that Ginger
  3395. 2:04:31to template inside your anible playbook
  3396. 2:04:33I I would like to explain my anible
  3397. 2:04:35playbook and what we are going to
  3398. 2:04:36achieve with that anible Playbook so
  3399. 2:04:39here I'm just going to install Light
  3400. 2:04:40httpd web server onto my Linux machine
  3401. 2:04:44so that's the first task which I'm just
  3402. 2:04:46going to do secondly here in the uh
  3403. 2:04:49second task I'm just creating a
  3404. 2:04:51configuration this is an httpd conf or
  3405. 2:04:54like a server configuration which I'm
  3406. 2:04:56planning to replace with my custom
  3407. 2:04:59configuration and my custom
  3408. 2:05:01configuration I would like to start my
  3409. 2:05:03server on a port R so that's why I'm
  3410. 2:05:05just going to replace this particular
  3411. 2:05:07file this light httpd con which is
  3412. 2:05:10present on Etc and /l httpd directory so
  3413. 2:05:15I would like to replace this particular
  3414. 2:05:16file which is present over there and I
  3415. 2:05:18would like to replace this file with my
  3416. 2:05:20config dog 2 which is my ging 2 template
  3417. 2:05:24and here I'm just going to start finally
  3418. 2:05:26my light httpd server let's run this
  3419. 2:05:29Playbook and verify our Ginger 2
  3420. 2:05:31template whether it's working or not so
  3421. 2:05:33what you need to do you just need to
  3422. 2:05:34head over to readme file and here I have
  3423. 2:05:36written the command to execute this
  3424. 2:05:38particular anible Playbook so I'm just
  3425. 2:05:40going to copy this command go to
  3426. 2:05:42terminal and paste this
  3427. 2:05:45command so as you can see over here our
  3428. 2:05:48task has just finished so here I have
  3429. 2:05:50installed the light HTT TP web server
  3430. 2:05:52after that we have created our own
  3431. 2:05:55custom configuration for that server and
  3432. 2:05:57then finally we have started our server
  3433. 2:06:00so what I'm going to do next I'm just
  3434. 2:06:01going to SSH into my server and I'm just
  3435. 2:06:04going to verify my uh server
  3436. 2:06:06configuration whether we have properly
  3437. 2:06:09replaced those server configuration with
  3438. 2:06:11my Ginger 2 template or not so this is
  3439. 2:06:13my terminal and I'm just going to do I'm
  3440. 2:06:15just going to SSH into my server uh
  3441. 2:06:17which is my ec2 instance running on AWS
  3442. 2:06:20simply hit enter
  3443. 2:06:22and here I can uh see that I have logged
  3444. 2:06:24in into my uh Linux server I'm just
  3445. 2:06:26going to clear the screen and I'm just
  3446. 2:06:28going to run the cat command to go to
  3447. 2:06:30the ETC light HTTP and then I'm just
  3448. 2:06:33going to view the con
  3449. 2:06:36file and if we scroll up then you can
  3450. 2:06:39see this is the server port and the
  3451. 2:06:40value which I have assigned over here is
  3452. 2:06:4280 so that's how we we are just able to
  3453. 2:06:45replace our custom configuration for our
  3454. 2:06:48server so that's a one place I have
  3455. 2:06:50modified but you can use this Ginger to
  3456. 2:06:53template concept to uh replace or put
  3457. 2:06:55your custom configuration on a various
  3458. 2:06:57places so it is not limited that you can
  3459. 2:06:59only replace one configuration but you
  3460. 2:07:02can replace more than one configuration
  3461. 2:07:04so that you get more dynamicity and more
  3462. 2:07:06custom configuration which you can put
  3463. 2:07:08onto the servers so that's a one use
  3464. 2:07:11case but you can use this concept to
  3465. 2:07:13customize your configuration at certain
  3466. 2:07:16extent so that will really help you to
  3467. 2:07:18put your custom configuration and make
  3468. 2:07:20your anle lebook more
  3469. 2:07:23powerful all right so now you have seen
  3470. 2:07:25the gingu template and how to use the
  3471. 2:07:27gingu template to put your custom server
  3472. 2:07:30configuration but I just want to take
  3473. 2:07:32the same example and I just want to take
  3474. 2:07:35it uh to the next level where I'm just
  3475. 2:07:37going to change the port from 80 to 9090
  3476. 2:07:40so why I'm doing this because you can
  3477. 2:07:42use the same n Playbook and instead of
  3478. 2:07:44running on a port 80 you can change the
  3479. 2:07:46port to run it on a different port but
  3480. 2:07:48that's not an ideal scenario but it can
  3481. 2:07:51happen happen in future that you want to
  3482. 2:07:52change some of your configuration and
  3483. 2:07:54instead of running a server on a
  3484. 2:07:56particular Port you want to change to
  3485. 2:07:58run that Port that server onto different
  3486. 2:08:00port so that's a hypothetical scenario
  3487. 2:08:03but that's not in actual real use cases
  3488. 2:08:05but something similar can happen into
  3489. 2:08:07your own configuration also so what I'll
  3490. 2:08:10do over here so instead of running it on
  3491. 2:08:11a 80 I'm just going to change it to run
  3492. 2:08:13it on a
  3493. 2:08:149090 so with the help of this anible
  3494. 2:08:18Playbook and Ginger 2 template you can
  3495. 2:08:19simply update your anible play and pass
  3496. 2:08:22a new value to your server configuration
  3497. 2:08:25so here I'm just passing the value 9090
  3498. 2:08:28I'll just save this changes and I'll
  3499. 2:08:30head over to my
  3500. 2:08:32terminal uh go to my ncble playbook I'm
  3501. 2:08:35just going to clear the screen and rerun
  3502. 2:08:37the playable so this time what it is
  3503. 2:08:39going to do it is just going to update
  3504. 2:08:41the server configuration and it is going
  3505. 2:08:43to start my same server on a different
  3506. 2:08:46port which is 9090 so here you can see
  3507. 2:08:49uh it has changed the configuration and
  3508. 2:08:51you can see the color has changed over
  3509. 2:08:53here which means our server
  3510. 2:08:55configuration has been changed and what
  3511. 2:08:58we can do we can again go back to the
  3512. 2:09:00another uh terminal over here where we
  3513. 2:09:02have already logged in I'm just going to
  3514. 2:09:03clear the screen over here and we are
  3515. 2:09:05just going to verify whether our changes
  3516. 2:09:07has been reflected there or not so I'm
  3517. 2:09:09just going to rerun the cat command to
  3518. 2:09:11view the changes and if we scroll up and
  3519. 2:09:14here you can see so we are able to
  3520. 2:09:16update our server configuration just by
  3521. 2:09:18running the Playbook so that's the power
  3522. 2:09:21of your Ginger to template which you can
  3523. 2:09:23extend and customize your anible
  3524. 2:09:26playbook so that was all about the
  3525. 2:09:28ginger to template in anible Playbook
  3526. 2:09:30and so far we have covered sixth chapter
  3527. 2:09:33and in the next chapter we will be
  3528. 2:09:35talking more about the deployment
  3529. 2:09:37strategy and where we will talk about
  3530. 2:09:39like how you can use the anible Playbook
  3531. 2:09:41on a single server and when you can use
  3532. 2:09:43the same anible Playbook to run on a
  3533. 2:09:45multiple server so that's going to be
  3534. 2:09:48the next Topic in this series and if you
  3535. 2:09:50new to this channel then please please
  3536. 2:09:51considering subscribing to this channel
  3537. 2:09:53where you will see the similar content
  3538. 2:09:55onto the devops especially like a
  3539. 2:09:57terraform anible AWS gcp kubernetes and
  3540. 2:10:01Docker so please considering subscribing
  3541. 2:10:03to this Channel and if you have any
  3542. 2:10:05question related to the today's session
  3543. 2:10:06then please put down into the comment
  3544. 2:10:08section and I'll try to get back to you
  3545. 2:10:10so see you into the next session of the
  3546. 2:10:11sensible series till then take care and
  3547. 2:10:15bye-bye there are various deployment
  3548. 2:10:17strategies when you are using anible to
  3549. 2:10:19automate your deployment processes but
  3550. 2:10:21on a very high level you can put the
  3551. 2:10:23deployment strategies into two category
  3552. 2:10:25one is the single server deployment and
  3553. 2:10:27second is the multi-server deployment
  3554. 2:10:29for ansible in this lab session we are
  3555. 2:10:31going to discuss about the deployment
  3556. 2:10:33strategies and specifically we will be
  3557. 2:10:35talking about how to manage the
  3558. 2:10:36deployment on all the servers when
  3559. 2:10:38you're working with the anible second we
  3560. 2:10:40are just going to take a look on how to
  3561. 2:10:42deploy or manage the deployment on a
  3562. 2:10:44subset or a selected server out of all
  3563. 2:10:47the servers and finally we are just
  3564. 2:10:49going to take a look onto the blue and
  3565. 2:10:51green green strategy also so how you can
  3566. 2:10:53implement the blue and green deployment
  3567. 2:10:55strategy for your anible automation
  3568. 2:10:57before we start talking about the
  3569. 2:10:59complex deployment strategy let's take a
  3570. 2:11:01very simple example and understand how
  3571. 2:11:03you will manage the deployment on a
  3572. 2:11:05single server let's take a look onto the
  3573. 2:11:07project structure where I have created a
  3574. 2:11:09sample project in which I'm targeting
  3575. 2:11:11only single server deployment with my
  3576. 2:11:13anible playbook so this is the host file
  3577. 2:11:16which is present inside my uh project
  3578. 2:11:18and this is the definition or the
  3579. 2:11:20configuration which is present inside my
  3580. 2:11:22host file and you can see over here
  3581. 2:11:24that's only one IP address which I have
  3582. 2:11:26mentioned so this is the remote server
  3583. 2:11:28where I'll be doing the deployment and
  3584. 2:11:31just to keep the thing simple what I'll
  3585. 2:11:32be doing I'll be installing the python
  3586. 2:11:34on my remote server using this anible
  3587. 2:11:37Playbook and since our host file only
  3588. 2:11:40contains single server so this whole
  3589. 2:11:42Playbook will be responsible for
  3590. 2:11:43managing the deployment on a single
  3591. 2:11:46server okay that's being said let's take
  3592. 2:11:48a look onto the anible Playbook command
  3593. 2:11:50so here you you can see this is the
  3594. 2:11:52anible Playbook command which I have
  3595. 2:11:53written over here so this is the anible
  3596. 2:11:55Playbook keyword which you need to
  3597. 2:11:57mention then you need to specify the
  3598. 2:11:59inventory and the host file which you
  3599. 2:12:01can see over here so this is the host
  3600. 2:12:03file path where I have defined my host
  3601. 2:12:06host IP and after that the actual
  3602. 2:12:09Playbook name so the name of the
  3603. 2:12:10Playbook is anible deployment strategy.
  3604. 2:12:12yml so that's the command which you need
  3605. 2:12:15to execute to run this particular
  3606. 2:12:17Playbook one thing to keep in mind over
  3607. 2:12:19here since it's a single server
  3608. 2:12:21deployment and I have not used any host
  3609. 2:12:23or I have not limit this particular
  3610. 2:12:25Playbook to run on a single host since I
  3611. 2:12:28have not specified any host inside my
  3612. 2:12:30anible command I'm talking about this
  3613. 2:12:32particular anible command so what it
  3614. 2:12:34will do it will just go and execute this
  3615. 2:12:36an Playbook on this default host which I
  3616. 2:12:39have mentioned inside my host file so
  3617. 2:12:41you just simply need to run this
  3618. 2:12:43Playbook and it will execute the whole
  3619. 2:12:45uh anible deployment for that particular
  3620. 2:12:48host and don't worry we are just going
  3621. 2:12:50to perform a in the second part of this
  3622. 2:12:52lab session where I'm just going to show
  3623. 2:12:54you like how to do the single server
  3624. 2:12:55deployment and how to do the multi-
  3625. 2:12:57server deployment using an all right so
  3626. 2:13:00now we have seen the single server
  3627. 2:13:01deployment and how to manage the single
  3628. 2:13:03server host inside our host file let's
  3629. 2:13:06discuss more onto the multi- server
  3630. 2:13:07deployment using anel so here onto the
  3631. 2:13:10screen I have taken one example and this
  3632. 2:13:12is my anel project which you can see and
  3633. 2:13:15this is the host file where I have
  3634. 2:13:16defined the multi- server host
  3635. 2:13:18configuration so this is the host file
  3636. 2:13:21which I have uh taken a screenshot over
  3637. 2:13:23here and I have categorized my host into
  3638. 2:13:26two category one is the blue and second
  3639. 2:13:28one is the green so in the blue uh like
  3640. 2:13:30a category I have two uh IP addresses so
  3641. 2:13:33these are the two remote machines which
  3642. 2:13:35I am using and here in the green also I
  3643. 2:13:38have specified two remote IPS so here
  3644. 2:13:40this is the third and this is the fourth
  3645. 2:13:42server so here I'm managing the fourth
  3646. 2:13:44server and I'm trying to deploy or
  3647. 2:13:47automate this deployment process using
  3648. 2:13:49the anible for our four remote host
  3649. 2:13:51machine now you might be wondering like
  3650. 2:13:54what is this blue and green category so
  3651. 2:13:56whenever you're having more than one
  3652. 2:13:58server then it is always difficult to
  3653. 2:14:00remember the IP addresses of each server
  3654. 2:14:03so what we do in anible is like we
  3655. 2:14:05create a category and here we have
  3656. 2:14:06created two category one is the blue and
  3657. 2:14:08second one is the green let's talk about
  3658. 2:14:10the green category so in the green
  3659. 2:14:12category in our example we are having
  3660. 2:14:14two servers and those two servers are
  3661. 2:14:17actively running in the production
  3662. 2:14:18environment and actively serving the
  3663. 2:14:20reest from active customer so our
  3664. 2:14:23applications are live and those are
  3665. 2:14:25accessible uh by our clients but the
  3666. 2:14:28blue category is also a production
  3667. 2:14:30environment but that is not actively
  3668. 2:14:32serving the request from the clients so
  3669. 2:14:35just to ease out the thing I will put
  3670. 2:14:37active over here and this one is passive
  3671. 2:14:41over here so what happens over here is
  3672. 2:14:44like whenever you're doing the release
  3673. 2:14:46then what you're going to do you're just
  3674. 2:14:47going to perform the production release
  3675. 2:14:49on a blue category of a server because
  3676. 2:14:52your blue category of a production
  3677. 2:14:54server are not serving the actual
  3678. 2:14:56client's request but the green category
  3679. 2:14:58of a servers are actually serving the
  3680. 2:15:00client request so you are not going to
  3681. 2:15:02touch the green side of it you just stay
  3682. 2:15:05away during the production release
  3683. 2:15:06you're just going to do the deployment
  3684. 2:15:08and release on a blue category of
  3685. 2:15:10servers and once you done with those
  3686. 2:15:12deployment on your blue category of a
  3687. 2:15:14servers then what you're going to do
  3688. 2:15:16you're just going to decommission or
  3689. 2:15:18you're just going to put off the uh
  3690. 2:15:20traffic onto the green side of the
  3691. 2:15:22server so you're just going to cut the
  3692. 2:15:24all the traffic which are coming towards
  3693. 2:15:26the green and then you're just going to
  3694. 2:15:27redirect all this traffic towards the
  3695. 2:15:29blue category the benefit of this
  3696. 2:15:32deployment strategy with anel is that
  3697. 2:15:34you don't have to put the downtime on
  3698. 2:15:36your production server your applications
  3699. 2:15:38are always available and you just need
  3700. 2:15:40to switch the server from green to the
  3701. 2:15:43blue server that being said then how
  3702. 2:15:45you're going to implement this thing
  3703. 2:15:46using the anible Playbook command so
  3704. 2:15:49here there are a couple of flags which
  3705. 2:15:50you need need to use so whenever you're
  3706. 2:15:52just doing the production deployment on
  3707. 2:15:53a blue side then you just need to use
  3708. 2:15:55this particular limit flag so just type
  3709. 2:15:59your anible playbook command onto your
  3710. 2:16:01terminal and just Supply this flag at
  3711. 2:16:03the end of this and at the end of your
  3712. 2:16:05anible playbook command and this whole
  3713. 2:16:08deployment will run onto the blue
  3714. 2:16:10category of servers and here is an
  3715. 2:16:12example command which I have uh
  3716. 2:16:14mentioned over here there is a
  3717. 2:16:15screenshot so here you can see this is
  3718. 2:16:16the limit flag which I'm using along
  3719. 2:16:18with my anible playbook command so this
  3720. 2:16:21is the way you can just manage the uh
  3721. 2:16:23deployment uh using this limit flag and
  3722. 2:16:26you can Target the servers which are
  3723. 2:16:28present under the blue category let's
  3724. 2:16:30start with the demo and here onto the
  3725. 2:16:32screen you can see this is the part 12
  3726. 2:16:34and this is the project which I have
  3727. 2:16:35created for this deployment strategy and
  3728. 2:16:37I'll put the link of this particular
  3729. 2:16:39project into the GitHub section so feel
  3730. 2:16:41free to clone that particular project
  3731. 2:16:43all right so talking about this project
  3732. 2:16:45so first of all let's take a look onto
  3733. 2:16:47the host file and first we will Target
  3734. 2:16:49onto the single server deployment so
  3735. 2:16:51this is the host file and inside the
  3736. 2:16:53host file I have created a default and
  3737. 2:16:55default category and inside the default
  3738. 2:16:57category I have mentioned the IP address
  3739. 2:16:59of my remote machine so I'm just going
  3740. 2:17:02to run this Playbook and this Playbook
  3741. 2:17:04is going to run on this default machine
  3742. 2:17:06this this default remote server so what
  3743. 2:17:08I'm going to do I'm just going to open
  3744. 2:17:10the readme file over here I'm just going
  3745. 2:17:12to copy this
  3746. 2:17:14command go to terminal I'm just going to
  3747. 2:17:17clear the screen I'll just go to the
  3748. 2:17:19directory where my project
  3749. 2:17:22is clear the screen I'm just going to
  3750. 2:17:24shorten this path so that it is visible
  3751. 2:17:28to you
  3752. 2:17:30also okay I'm just going to clear it and
  3753. 2:17:32I'm just going to paste the command over
  3754. 2:17:33here and here you can see in this
  3755. 2:17:35Playbook command I'm not specifying any
  3756. 2:17:37limit so I just want this Playbook to
  3757. 2:17:39run on all the host which are present
  3758. 2:17:42inside my host file simply type enter
  3759. 2:17:45type
  3760. 2:17:47yes now my NC Playbook has just finished
  3761. 2:17:50and it has inst install python onto my
  3762. 2:17:52remote server with this particular IP
  3763. 2:17:54address all right so now we have seen
  3764. 2:17:56the single server deployment strategy
  3765. 2:17:58using the Nal let's update the host file
  3766. 2:18:00and put the blue and green category
  3767. 2:18:02along with the servers so I'm just going
  3768. 2:18:04to go to my project I'm just going to
  3769. 2:18:06open my host file and I'm just going to
  3770. 2:18:09erase everything from here and I'm just
  3771. 2:18:11going to add the blue and green category
  3772. 2:18:13along with the remote server server IP
  3773. 2:18:16address let's open the readme file over
  3774. 2:18:18here once again and here I have
  3775. 2:18:20mentioned the anible Playbook command
  3776. 2:18:22with the limit flag so what you need to
  3777. 2:18:24do is you need to remove the line braks
  3778. 2:18:26over here otherwise you might not be
  3779. 2:18:28able to run the sensible Playbook okay
  3780. 2:18:30that's been done so I'm just going to
  3781. 2:18:32copy this command from here I'm just
  3782. 2:18:34going to head over to terminal I'm just
  3783. 2:18:36going to clear the screen and I'm just
  3784. 2:18:38going to place the command over here so
  3785. 2:18:40here you can see I'm just running the
  3786. 2:18:41sensible Playbook with the limit blue so
  3787. 2:18:43I'm just going to update the blue
  3788. 2:18:45category of servers so simply hit enter
  3789. 2:18:49type yes
  3790. 2:18:51all right so now my ncble playbook has
  3791. 2:18:53just finished and as you can see there
  3792. 2:18:55are two IP address which has been
  3793. 2:18:57updated so one of them is like this one
  3794. 2:18:5952 59 205 and 47 so this particular one
  3795. 2:19:03which I have highlighted which I have
  3796. 2:19:04already uh where I have already
  3797. 2:19:07installed the python when I did the
  3798. 2:19:08single server deployment but this is the
  3799. 2:19:11second IP uh which is from the blue
  3800. 2:19:13category and that has been updated or
  3801. 2:19:15where I have installed python using the
  3802. 2:19:17anel and we can verify both the IP
  3803. 2:19:19addresses so let's let's open the host
  3804. 2:19:21file once again and I'm just going to
  3805. 2:19:23open the terminal over here also so that
  3806. 2:19:25you can see so as you can see over here
  3807. 2:19:28so 5259 205 and 47 so that's the IP
  3808. 2:19:32address under blue category and the
  3809. 2:19:33second IP address was 18 19423 and 12 so
  3810. 2:19:38that's the second IP address so these
  3811. 2:19:40are the two uh category of a those two
  3812. 2:19:43servers under the blue category I have
  3813. 2:19:45updated uh using the N so that's how
  3814. 2:19:47you're just going to limit uh the
  3815. 2:19:49servers which you want to put under the
  3816. 2:19:52deployment of anible and using the same
  3817. 2:19:54limit flag you do the production
  3818. 2:19:56deployment for the green category of a
  3819. 2:19:58servers also you just need to change the
  3820. 2:20:00name of the limit flag so this is how
  3821. 2:20:03you're just going to manage the
  3822. 2:20:04deployment strategy or you're just going
  3823. 2:20:06to manage the deployment on a
  3824. 2:20:08multi-server environment like generally
  3825. 2:20:10we have in our production I hope this
  3826. 2:20:12short session on this deployment
  3827. 2:20:13strategies with anel will help you to
  3828. 2:20:15manage and streamline your production
  3829. 2:20:17strategies uh of deployment with anel
  3830. 2:20:20and if you're interested into the
  3831. 2:20:21similar devops concept on anible
  3832. 2:20:24terraform AWS kubernetes Helm chart
  3833. 2:20:26Docker then please considering
  3834. 2:20:28subscribing to this channel where I keep
  3835. 2:20:29on sharing the similar content on a
  3836. 2:20:31weekly basis so see you into the next
  3837. 2:20:33session of anible or devops till then
  3838. 2:20:35take care and
  3839. 2:20:37bye-by error handling is really a
  3840. 2:20:40powerful feature which helps you to
  3841. 2:20:42address the unexpected errors which may
  3842. 2:20:44occur when you are running your anible
  3843. 2:20:45playbook let's talk about the couple of
  3844. 2:20:47scenarios which might help you to
  3845. 2:20:49understand why you should need need
  3846. 2:20:50error handling in your anible playbook
  3847. 2:20:53let's assume that you have a two server
  3848. 2:20:55and you need to copy a particular file
  3849. 2:20:57onto both the server but what happens is
  3850. 2:21:00that when you're running an anible
  3851. 2:21:01Playbook you notice that one of the
  3852. 2:21:03server is offline and you cannot reach
  3853. 2:21:04to that particular server and once you
  3854. 2:21:06cannot reach to that particular server
  3855. 2:21:08that means you cannot copy a file to
  3856. 2:21:10that particular server but although the
  3857. 2:21:12second server is online and you are
  3858. 2:21:14still able to perform a copy onto that
  3859. 2:21:16server so if you don't use any kind of
  3860. 2:21:19error handling over here here then your
  3861. 2:21:21anible playbook will fail and eventually
  3862. 2:21:23you will not be able to copy the same
  3863. 2:21:25file onto the another server which is up
  3864. 2:21:27and running so in such a scenario what
  3865. 2:21:29you can do you can just use the ignore
  3866. 2:21:31error flag inside your anible playbook
  3867. 2:21:34so what it will do it will just let
  3868. 2:21:36ignore that particular error when you're
  3869. 2:21:38trying to execute the anible Playbook so
  3870. 2:21:40what will happen is that you will just
  3871. 2:21:43skip that particular error and but you
  3872. 2:21:44will move to the next server and you
  3873. 2:21:46will just copy that file onto the second
  3874. 2:21:48server so with the help of the sign
  3875. 2:21:50error you can just ignore such kind of
  3876. 2:21:52Errors happening into your anible
  3877. 2:21:54playbook let's take another use case
  3878. 2:21:56where you want to forcefully fail the
  3879. 2:21:58execution of your anible playbook and
  3880. 2:22:00for this use case let's assume that you
  3881. 2:22:02are trying to copy a config file which
  3882. 2:22:04is really necessary for your production
  3883. 2:22:06deployment but what you notice is that
  3884. 2:22:08that the destination path is incorrect
  3885. 2:22:10and you are not able to copy that
  3886. 2:22:12particular config file onto your
  3887. 2:22:13destination server and since this config
  3888. 2:22:16file is really important for your
  3889. 2:22:17production deployment so you want to
  3890. 2:22:19forcefully fail that anible Playbook so
  3891. 2:22:21in such kind of a scenario you need to
  3892. 2:22:23use a flag any error fatal so this
  3893. 2:22:26particular flag will help you to
  3894. 2:22:28forcefully stop the anible Playbook
  3895. 2:22:30execution and you need to fix that error
  3896. 2:22:32before moving to the next deployment now
  3897. 2:22:35I have explained to you the couple of
  3898. 2:22:36flags which you can use for your anible
  3899. 2:22:38playbook now I would like to switch over
  3900. 2:22:40to my desktop and show you like how we
  3901. 2:22:42can use those flag inside our anible
  3902. 2:22:45playbook for error handling all right so
  3903. 2:22:47this is my anible playbook and the first
  3904. 2:22:49task where we are just going to see is
  3905. 2:22:51the ignore errors flag so here let me
  3906. 2:22:53explain this particular task and how we
  3907. 2:22:55are going to simulate this particular
  3908. 2:22:57error and then we are just going to
  3909. 2:22:58ignore that particular error so here at
  3910. 2:23:00line number four if you pay attention
  3911. 2:23:02then I'm just trying to copy index.html
  3912. 2:23:05to my remote server at this particular
  3913. 2:23:08path and the path is home u 2 so I'm
  3914. 2:23:10just going to first of all show you my
  3915. 2:23:12remote server so this is my remote
  3916. 2:23:15server and if I do the PWD so this is
  3917. 2:23:17the path where I would like to copy that
  3918. 2:23:19index. HTML
  3919. 2:23:21but to simulate this ignore error what I
  3920. 2:23:24did is I just didn't provided the
  3921. 2:23:26index.html so this index.html is
  3922. 2:23:29completely missing so when this task run
  3923. 2:23:31then it will not be able to find the
  3924. 2:23:32index. HTML and if it is not able to
  3925. 2:23:35find the index. HTML then it will result
  3926. 2:23:38into error and at line number six I have
  3927. 2:23:40put the flag that ignore errors that's
  3928. 2:23:43true so which means if there is any
  3929. 2:23:45error in involved in this particular
  3930. 2:23:47task then this particular flag flag is
  3931. 2:23:50going to to ignore that particular error
  3932. 2:23:52let's run this Playbook and if you are
  3933. 2:23:54looking for this particular project then
  3934. 2:23:55I'll provide the GitHub repository link
  3935. 2:23:57of this particular project into the
  3936. 2:23:59description section so feel free to use
  3937. 2:24:01that particular Rao so here I have
  3938. 2:24:03created a readme file uh which you can
  3939. 2:24:05copy The anible Playbook command from
  3940. 2:24:07here and also I would like to show you
  3941. 2:24:10uh that this index.html so ideally I'm
  3942. 2:24:14expecting this index.html to be present
  3943. 2:24:16along with my main. yml but this
  3944. 2:24:18particular file I have not provided it
  3945. 2:24:20all over here so that's just a a small
  3946. 2:24:22thing I would like to mention before
  3947. 2:24:23running the anible playable so I'm just
  3948. 2:24:26going to head over to my terminal I'm
  3949. 2:24:28just going to open another one I'm just
  3950. 2:24:30going to clear the screen and I'm just
  3951. 2:24:31going to paste the command over here and
  3952. 2:24:33simply hit
  3953. 2:24:37enter and here you can see uh index HTML
  3954. 2:24:41copy with ignore error so that was our
  3955. 2:24:43task name so you which you can see over
  3956. 2:24:45here that was our task name and if you
  3957. 2:24:47open the terminal then here you can see
  3958. 2:24:50could not find or access index.html so
  3959. 2:24:53which tells you that this index.html is
  3960. 2:24:55completely missing and anible Playbook
  3961. 2:24:57couldn't find that
  3962. 2:24:59index.html but since we have used that
  3963. 2:25:01particular flag so it is ignoring this
  3964. 2:25:03particular error which you can see over
  3965. 2:25:05here and at the same time if you look at
  3966. 2:25:08uh the final result of the sensible
  3967. 2:25:10Playbook then you will see that it has
  3968. 2:25:12completed but it has ignored that
  3969. 2:25:14particular task so this is how you're
  3970. 2:25:16just going to use the ignore error flag
  3971. 2:25:18inside your anible playbook where you
  3972. 2:25:20want to intentionally ignore any error
  3973. 2:25:23which is happening inside your anible
  3974. 2:25:25task moving to the next anible task
  3975. 2:25:27where I would like to forcefully fail my
  3976. 2:25:29anible playbook and for that I'm just
  3977. 2:25:31going to use the any errors fatal flag
  3978. 2:25:34inside my anible task so here I'm just
  3979. 2:25:36going to take the same example so here
  3980. 2:25:38again I'm just trying to copy the
  3981. 2:25:39index.html and this index.html is
  3982. 2:25:42missing and I'm just trying to copy at
  3983. 2:25:44the same path but here I just put some
  3984. 2:25:47conditions over here so the first
  3985. 2:25:49condition which I have put over here is
  3986. 2:25:50the any errors fatle which is true if
  3987. 2:25:53this flag is true and if there are any
  3988. 2:25:55error associated with this particular
  3989. 2:25:57task then my whole anible Playbook is
  3990. 2:25:59going to fail but I need to provide the
  3991. 2:26:02condition when this condition is me then
  3992. 2:26:06make this particular task fail for this
  3993. 2:26:08particular anible Playbook so we need to
  3994. 2:26:10use or we need to specify a condition
  3995. 2:26:12and that condition you can specify using
  3996. 2:26:15the failed van so you need to use two
  3997. 2:26:17attributes over here so first attribute
  3998. 2:26:19we are just going to use is any errors
  3999. 2:26:21fatle so that your whole anible Playbook
  4000. 2:26:23will fail but you need to specify the
  4001. 2:26:25condition when this particular condition
  4002. 2:26:27is met then make this whole anible
  4003. 2:26:29Playbook fail and for that we are just
  4004. 2:26:31going to use the fail when flag inside
  4005. 2:26:33your anible task let's take a closer
  4006. 2:26:36look onto the failed when condition and
  4007. 2:26:38how I specified it so here at line
  4008. 2:26:40number 17 you will see a message like
  4009. 2:26:43could not find or access so this is a
  4010. 2:26:45particular error message I'm looking
  4011. 2:26:47into but where I'm looking this
  4012. 2:26:49particular error message so if you take
  4013. 2:26:51a look onto the previous task then here
  4014. 2:26:54I'm just trying to capture the result of
  4015. 2:26:57this particular operation which is a
  4016. 2:26:59copy operation so here it is trying to
  4017. 2:27:01perform a copy operation and whatever
  4018. 2:27:03happens in that operation I'm just
  4019. 2:27:05trying to register that output into this
  4020. 2:27:07particular variable that is copy result
  4021. 2:27:10so what I'm expecting is that in that
  4022. 2:27:13copy result uh variable I'm expecting a
  4023. 2:27:16message and that message should contain
  4024. 2:27:18could not find or access although that
  4025. 2:27:21message is going to be a really long one
  4026. 2:27:23but I just want to find this particular
  4027. 2:27:24words inside that message so if you're
  4028. 2:27:27trying to copy a particular file and if
  4029. 2:27:29that file doesn't exist then it will
  4030. 2:27:31result some error and that result error
  4031. 2:27:33message will contain could not find or
  4032. 2:27:35access index.html and I'm just trying to
  4033. 2:27:38find that particular keywords inside
  4034. 2:27:40that particular message so once that
  4035. 2:27:43condition or when once that keyword I'm
  4036. 2:27:45able to find it then I'm just going to
  4037. 2:27:47evaluate that particular condition so
  4038. 2:27:49here have specified this particular
  4039. 2:27:51string and it should be present into the
  4040. 2:27:53copy result. message and if it is
  4041. 2:27:55present then I'm just going to make it
  4042. 2:27:57fail and this condition will get true
  4043. 2:27:59and similarly there will be one more
  4044. 2:28:01flag which will be coming along with
  4045. 2:28:03this copy result because this is a like
  4046. 2:28:05a registered variable and it will have a
  4047. 2:28:06lot of attribute which I'm just going to
  4048. 2:28:08show you next so inside that I also like
  4049. 2:28:11to check whether that particular task
  4050. 2:28:13failed status is true so when these both
  4051. 2:28:17conditions are met then I'm just going
  4052. 2:28:19to evaluate these condition and both the
  4053. 2:28:21conditions are true and then I'm just
  4054. 2:28:23going to make this uh particular any
  4055. 2:28:25errors fatal flag true and this whole
  4056. 2:28:28anible Playbook will fail but before we
  4057. 2:28:30run this anible Playbook I would like to
  4058. 2:28:31enable one more task where I would like
  4059. 2:28:33to show you that register variable and
  4060. 2:28:35what it holds inside it so here I have
  4061. 2:28:38just put a debug on that particular
  4062. 2:28:40register variable so I'm just going to
  4063. 2:28:42enable this particular task also so that
  4064. 2:28:44you can see what's happening inside or
  4065. 2:28:45what are the values present inside this
  4066. 2:28:47particular copy result variable so I
  4067. 2:28:49have just enable this particular debug
  4068. 2:28:52so when I'm just going to run the
  4069. 2:28:53sensible Playbook so it is going to spit
  4070. 2:28:55out uh what are the content inside this
  4071. 2:28:57particular message and then we are just
  4072. 2:28:59going to see like what are the condition
  4073. 2:29:01which it is evaluating inside this third
  4074. 2:29:03task okay so I'm just going to open the
  4075. 2:29:05terminal over here I'm just going to
  4076. 2:29:07clear the screen and I'm just going to
  4077. 2:29:09run the ncble
  4078. 2:29:11Playbook and here you can see uh we'll
  4079. 2:29:14just start from the first so this is our
  4080. 2:29:16first use case where we have ignored
  4081. 2:29:18that particular error now second and
  4082. 2:29:20string variable from men Playbook so
  4083. 2:29:22this is where I'm just trying to print
  4084. 2:29:24the values or whatever message which is
  4085. 2:29:26present inside that copy uncore result
  4086. 2:29:28variable which I have registered so
  4087. 2:29:30which you can see over here I'm just
  4088. 2:29:32trying to print the values onto the
  4089. 2:29:34console so that I can see what are the
  4090. 2:29:35values present inside this particular
  4091. 2:29:37register variable okay so the key thing
  4092. 2:29:40which we need to look over here is we
  4093. 2:29:42need to find this particular text inside
  4094. 2:29:44that message and also the uh flag which
  4095. 2:29:47is like copy result. should be true
  4096. 2:29:50so I'm just going to open the terminal
  4097. 2:29:52and uh first of all this is the variable
  4098. 2:29:55that is copy underscore result that's
  4099. 2:29:56okay and then I'm just going to find the
  4100. 2:29:59keyword so here you can see could not
  4101. 2:30:00find or access so this particular
  4102. 2:30:03keyword I'm just trying to find as an
  4103. 2:30:04string inside that particular variable
  4104. 2:30:07so yeah that is present and also I'm
  4105. 2:30:10just going to try to find this copy
  4106. 2:30:12result and here is the file and that is
  4107. 2:30:14true so these are the two condition I
  4108. 2:30:17was force forcing uh in that particular
  4109. 2:30:19task to be evaluated and these both
  4110. 2:30:22conditions are met and once these two
  4111. 2:30:24conditions are met then I'm just making
  4112. 2:30:26this whole anible Playbook fail with the
  4113. 2:30:28any errors fatal fly so if you move down
  4114. 2:30:31further then here you can see here I'm
  4115. 2:30:33just trying to copy using failed when
  4116. 2:30:35and any error fatal flag and here you
  4117. 2:30:38can see this whole Playbook has just
  4118. 2:30:40failed and here you can see the final
  4119. 2:30:42status of our ncble Playbook that is
  4120. 2:30:44failed equals 1 and ignore equals 1 so
  4121. 2:30:46ignore one was our first use case and
  4122. 2:30:49this is our second task where we have
  4123. 2:30:51forcefully failed the whole anible
  4124. 2:30:53Playbook all right so now we have seen
  4125. 2:30:54the any errors fatal flag so what I'm
  4126. 2:30:56just going to do I'm just going to set
  4127. 2:30:58it to
  4128. 2:30:59false before moving to the next uh
  4129. 2:31:02anible task where I'm just going to show
  4130. 2:31:04you the another flag which is like a
  4131. 2:31:06changed B but to go to the next task
  4132. 2:31:09what I need to do is I need to first of
  4133. 2:31:10all enable this
  4134. 2:31:12one and why I set it to false because if
  4135. 2:31:15I don't set it to false then I will not
  4136. 2:31:17be able to run this particular task in
  4137. 2:31:20the next in my anible playbook so that's
  4138. 2:31:22why I need to forcefully set it to false
  4139. 2:31:24all right now I have set it to false the
  4140. 2:31:26next thing which I'm just trying to do
  4141. 2:31:27over here in this task is to use the
  4142. 2:31:29changed when so changed when is just an
  4143. 2:31:32another error handling kind of things in
  4144. 2:31:35anible pbook uh which tells you like if
  4145. 2:31:37something has changed onto the remote
  4146. 2:31:40server so that's where we are just going
  4147. 2:31:41to use the changed when uh flag inside
  4148. 2:31:44your anible playbook so what I'm just
  4149. 2:31:46going to do over here is that I'm just
  4150. 2:31:48going to touch a file so I'm just going
  4151. 2:31:50to create a simple file with the name my
  4152. 2:31:53my file.txt onto the my remote server
  4153. 2:31:56onto this particular location that is
  4154. 2:31:58homeor ub2 and I'm just going to show
  4155. 2:32:01you that whether that file is present or
  4156. 2:32:03not I'm just going to clear it the path
  4157. 2:32:05is home/ to LS and here you can see the
  4158. 2:32:09uh that particular directory is empty
  4159. 2:32:11and there is no file which is created
  4160. 2:32:12over there so this ncble Playbook what
  4161. 2:32:15it will do it will just create a file
  4162. 2:32:17that is my file.txt and it will register
  4163. 2:32:20that output of this particular command
  4164. 2:32:22into this particular variable and once
  4165. 2:32:25that uh output is registered into this
  4166. 2:32:27variable then I'm just going to check uh
  4167. 2:32:30that that RC uh request for change is
  4168. 2:32:33zero or not if it's zero that means that
  4169. 2:32:36particular file has been created and if
  4170. 2:32:38it's other than zero then that means
  4171. 2:32:40that file has not been created onto the
  4172. 2:32:42remote server now I would like to
  4173. 2:32:44correct one thing over here I I
  4174. 2:32:45mentioned the name of this particular uh
  4175. 2:32:48RC flag is request for change but it's
  4176. 2:32:50actually a result code that's the actual
  4177. 2:32:52full form of that particular RC having
  4178. 2:32:55said that let's switch over to terminal
  4179. 2:32:56and run the sensible Playbook and we'll
  4180. 2:32:58see if we are able to create this
  4181. 2:32:59particular file or not onto my remote
  4182. 2:33:01server so I'm just going to open the
  4183. 2:33:03terminal and I'm just going to run the
  4184. 2:33:05command or to execute my anible
  4185. 2:33:08playbook and we'll start from the first
  4186. 2:33:10so here this was our first task for
  4187. 2:33:12ignoring the error secondly uh we were
  4188. 2:33:16just trying to uh set the value of any
  4189. 2:33:19errors ftles flag to false so now we are
  4190. 2:33:21not we are not forcefully failing our
  4191. 2:33:23flag so this task has also been passed
  4192. 2:33:26now the third task is which is this one
  4193. 2:33:28and which we are just going to evaluate
  4194. 2:33:30so here this is the name of the task
  4195. 2:33:31create a file if it does not exist so
  4196. 2:33:34I'm just going to head over to terminal
  4197. 2:33:36and this is the task and the changed
  4198. 2:33:38which means uh something has changed
  4199. 2:33:40onto this particular task and here you
  4200. 2:33:43can see the result that is changed
  4201. 2:33:44equals 1 which means that we are able to
  4202. 2:33:47create a file onto our remote server and
  4203. 2:33:49and the output is registered into this
  4204. 2:33:51variable and the value of that
  4205. 2:33:53particular uh code is zero so that means
  4206. 2:33:56our file has been created onto the
  4207. 2:33:58remote server and we can go to the
  4208. 2:34:00terminal and this is my terminal and I'm
  4209. 2:34:03just going to run the ls command and
  4210. 2:34:05here you can see my file.txt
  4211. 2:34:07so this is how you're just going to use
  4212. 2:34:10this particular changed van flag and you
  4213. 2:34:12can use this particular code associated
  4214. 2:34:15with this RC and you can specify it as a
  4215. 2:34:17zero so which means that something has
  4216. 2:34:19changed onto the remote server and that
  4217. 2:34:21change is creating a just a file so this
  4218. 2:34:24was just an example for using how you
  4219. 2:34:27can use the changed van flag inside your
  4220. 2:34:29anible task so this was a small lab
  4221. 2:34:31session on error handling in anible in
  4222. 2:34:34the next Lab session we are just going
  4223. 2:34:35to talk about the anible Vault and how
  4224. 2:34:37you can store the secure information
  4225. 2:34:39inside your anible Vault and that's
  4226. 2:34:41going to be a little bit a longer
  4227. 2:34:42session because there we will be
  4228. 2:34:44creating an anible Vault and then we
  4229. 2:34:45will be storing some Secrets inside that
  4230. 2:34:47enens Vault and using those Secret
  4231. 2:34:49inside our anible Playbook so that is
  4232. 2:34:52going to be the next session and if
  4233. 2:34:53you're interested into the similar
  4234. 2:34:54content on devops then please
  4235. 2:34:56considering subscribing to this channel
  4236. 2:34:57where I keep on sharing the similar
  4237. 2:34:59topics on a weekly basis so see you into
  4238. 2:35:01the next session of ncble or devops till
  4239. 2:35:03then take care and
  4240. 2:35:05bye-bye anible vault is a really
  4241. 2:35:08important concept when you want to
  4242. 2:35:09encrypt the data which you don't want to
  4243. 2:35:11show in a plain text format while
  4244. 2:35:13working with your anible playbook since
  4245. 2:35:15we are talking about the anible VA then
  4246. 2:35:17we should know the basic command on how
  4247. 2:35:19to operate on anible vault so the First
  4248. 2:35:22Command which we will take a look is
  4249. 2:35:24anible Vault create which will help you
  4250. 2:35:26to create an anible Vault from the
  4251. 2:35:28scratch second once you create an anible
  4252. 2:35:30Vault then how you're just going to edit
  4253. 2:35:32the content present inside the anible
  4254. 2:35:34Vault so the second command which we are
  4255. 2:35:36going to take a look is the anible Vault
  4256. 2:35:38edit and the third one is the anible
  4257. 2:35:41Vault view which can help you to view
  4258. 2:35:43the content in a readon mode present
  4259. 2:35:45inside your anible VA apart from anible
  4260. 2:35:48Vault basic command the second thing we
  4261. 2:35:50are going to take a look like how to use
  4262. 2:35:52your anible Vault when you're executing
  4263. 2:35:54your anible playbook and there are three
  4264. 2:35:57ways you can use your anible Vault the
  4265. 2:35:59first way to use your anible Vault while
  4266. 2:36:01executing or while running your anible
  4267. 2:36:03playbook is to supply the parameter ask
  4268. 2:36:05VA pass so when you supply this
  4269. 2:36:08parameter along with your anible
  4270. 2:36:10playbook command then you need to key in
  4271. 2:36:12or you need to enter your uh Vault
  4272. 2:36:14password and once you supply your Vault
  4273. 2:36:16password then you will be able to fetch
  4274. 2:36:18your secrets from your ncble vault which
  4275. 2:36:20are instored inside your encrypted yml
  4276. 2:36:23file the second way of using the ncble
  4277. 2:36:25vault is to store the password inside a
  4278. 2:36:28Vault password file so that you don't
  4279. 2:36:30need to key in or you don't need to
  4280. 2:36:32enter the password from the command line
  4281. 2:36:34you can simply store your password for
  4282. 2:36:36your Vault inside a plain text file and
  4283. 2:36:39then you can supply that file uh while
  4284. 2:36:41you're executing your anible playbook
  4285. 2:36:44and the third way of using the ncble
  4286. 2:36:45vault is to export the path of your
  4287. 2:36:47ncble Vault password file into the
  4288. 2:36:50environment variable and the benefit you
  4289. 2:36:52will get from that is you don't need to
  4290. 2:36:54enter the password of your anible Vault
  4291. 2:36:57and also you don't need to supply the
  4292. 2:36:59path of your ncble Vault password file
  4293. 2:37:01while you're executing the ncble
  4294. 2:37:03Playbook you can just simply run your
  4295. 2:37:04ncble playbook let's switch to my code
  4296. 2:37:07editor and the first thing we'll start
  4297. 2:37:09is by creating our anible vault so this
  4298. 2:37:11is my code editor and this is the part
  4299. 2:37:1314 and this whole project is available
  4300. 2:37:16onto my GitHub repository so I'll post
  4301. 2:37:18the link of my GitHub repository into
  4302. 2:37:20the description section so feel free to
  4303. 2:37:22clone this particular code repository
  4304. 2:37:24for your own use let's start with the
  4305. 2:37:26walk through of My ncble Vault project
  4306. 2:37:28so here this is the part 14 anible VA
  4307. 2:37:31which I have already created and inside
  4308. 2:37:33that project you will find a readme file
  4309. 2:37:35which I have already opened over here so
  4310. 2:37:37here I have written down all the
  4311. 2:37:38commands which I'm just going to use
  4312. 2:37:40inside this particular demo so the first
  4313. 2:37:43thing which we are going to do is we are
  4314. 2:37:44just going to create an anible Vault and
  4315. 2:37:46for that the command is anible VA create
  4316. 2:37:49and then after that you need to supply
  4317. 2:37:51the path so here I will be creating My
  4318. 2:37:53anible Vault yml inside the groups War
  4319. 2:37:56directory and the name of my vault yml
  4320. 2:37:58is my vault. yml I'll copy the command
  4321. 2:38:01from here to create my anible Vault so
  4322. 2:38:04I'll copy the command I'll go to
  4323. 2:38:06terminal and I'll just past the command
  4324. 2:38:08over here hit enter and as soon as you
  4325. 2:38:11hit the enter then it will ask you to
  4326. 2:38:13set a password for your anible VA so
  4327. 2:38:15here I'm just going to set a
  4328. 2:38:17password and it is again going to
  4329. 2:38:19confirm the same password which you have
  4330. 2:38:21entered so I'm just going to re enter my
  4331. 2:38:24password and here you can see our anible
  4332. 2:38:26vault has been created and now it has
  4333. 2:38:29opened my anible vault yml which is my
  4334. 2:38:32vault. yml so here this is open uh into
  4335. 2:38:36the edit mode and you can use the vi
  4336. 2:38:39command to enter your like a secret
  4337. 2:38:41inside your anible Vault so here I'm
  4338. 2:38:44just going to press I from the keyword
  4339. 2:38:46so that I can go into the insert mode
  4340. 2:38:48and the first thing which I'm just going
  4341. 2:38:49to create is like my uh Vault or maybe I
  4342. 2:38:53can type in like my secret and then I
  4343. 2:38:56can enter uh this
  4344. 2:38:59is the first
  4345. 2:39:02secret from anible Vault so this is the
  4346. 2:39:06uh secret text which I'm keying in
  4347. 2:39:08Inside My anible Vault and once you have
  4348. 2:39:11entered your secret then what you can do
  4349. 2:39:12you can press the escape from your
  4350. 2:39:14keyboard and then save and quit which is
  4351. 2:39:16w and Q and then hit enter
  4352. 2:39:19so by this way you are just going to
  4353. 2:39:21create your first anible Vault inside
  4354. 2:39:23your anible project and if you go back
  4355. 2:39:26to your project structure over here then
  4356. 2:39:28in the group ports you will find a file
  4357. 2:39:31that is myor wall. yml which has been
  4358. 2:39:34created and if you double click on it
  4359. 2:39:36then you can see this whole content
  4360. 2:39:38inside that particular file is encrypted
  4361. 2:39:41and you cannot view the content which we
  4362. 2:39:43have written which we have written a
  4363. 2:39:45simple message Inside My ncble Vault
  4364. 2:39:47since we have created our first n VA
  4365. 2:39:49then second command which I would like
  4366. 2:39:51to run is to view the content of my
  4367. 2:39:53anible VA so again go to this readme
  4368. 2:39:56file and here I have written the view
  4369. 2:39:58command to view the content of your
  4370. 2:40:00anible Vault and remember this is going
  4371. 2:40:02to be a readon mode you cannot edit
  4372. 2:40:04anything inside your anible Vault and
  4373. 2:40:07the command for that is anible Vault uh
  4374. 2:40:10after that you need to supply the
  4375. 2:40:12keyword view to view the content and
  4376. 2:40:14then after that you need to supply the
  4377. 2:40:15path of that particular file which you
  4378. 2:40:17have just created so I'm just going to
  4379. 2:40:19copy this command from here I'm just
  4380. 2:40:21going to head over to terminal and I'm
  4381. 2:40:22just going to paste the command and hit
  4382. 2:40:24enter and as soon as you hit the enter
  4383. 2:40:27to view the content of your anible Vault
  4384. 2:40:29then it is going to ask for the password
  4385. 2:40:31which you have set when you were when
  4386. 2:40:33you were creating that anible Vault so
  4387. 2:40:35I'm just going to supply the password
  4388. 2:40:37and hit enter and here you can see the
  4389. 2:40:39message uh or the secret message which
  4390. 2:40:41we have written inside our anible W so
  4391. 2:40:44the uh message which we have uh for that
  4392. 2:40:46created is first of all we have created
  4393. 2:40:48a variable that is myor secret and this
  4394. 2:40:51is the secret message which we have key
  4395. 2:40:53in inside my anible B well this is just
  4396. 2:40:56a demo but this anible Vault can be used
  4397. 2:40:59for securing your password which can be
  4398. 2:41:01your database passwords also so here you
  4399. 2:41:04can key in your strong password which is
  4400. 2:41:06really sensitive and you can place those
  4401. 2:41:08uh sensitive information inside your
  4402. 2:41:10anible Vault all right so now we have
  4403. 2:41:12created an anible Vault and we have seen
  4404. 2:41:15like how to view the content of My
  4405. 2:41:16anible Vault the next thing which I'm
  4406. 2:41:18just going to do is I'm just going to
  4407. 2:41:20use that anible Vault or the password
  4408. 2:41:23which we have or the secret text which
  4409. 2:41:25we have created or inserted inside my
  4410. 2:41:27anible VA into my anible playbook so
  4411. 2:41:30here if you take a look carefully so
  4412. 2:41:32this is the uh variable uh which is
  4413. 2:41:34storing my sensitive information so I'm
  4414. 2:41:37just going to use this variable to print
  4415. 2:41:39the value or to debug that particular
  4416. 2:41:41value inside my ncble pleb well this is
  4417. 2:41:44just a demo where that's why I'm just
  4418. 2:41:46I'm just using the debug but in case if
  4419. 2:41:48you want to use this for particular
  4420. 2:41:51let's say for example uh creating a
  4421. 2:41:53database connection and you want to
  4422. 2:41:54print uh or you want to use the database
  4423. 2:41:57password then you can use a similar
  4424. 2:41:59approach and just Supply your variable
  4425. 2:42:02where which is storing your database
  4426. 2:42:04password so this is just in another
  4427. 2:42:06example in the real time scenario how
  4428. 2:42:07you're just going to use this uh secret
  4429. 2:42:09values but for the time being I'm just
  4430. 2:42:12going to use this particular uh variable
  4431. 2:42:14from here I'm just going to copy it and
  4432. 2:42:17into my row to there is a task and there
  4433. 2:42:21is a main. yml so this is a a very debug
  4434. 2:42:24message which I just wanted to print and
  4435. 2:42:27here I have created a variable that is
  4436. 2:42:29war and here I'm just going to paste the
  4437. 2:42:31name of my variable that is my secret
  4438. 2:42:34now moving forward what I'll do I'll
  4439. 2:42:35just run this anible Playbook using my
  4440. 2:42:38anible P and for that you just need to
  4441. 2:42:40open the readme file over here and in
  4442. 2:42:42the second point I have written the
  4443. 2:42:43anible Playbook command to execute my
  4444. 2:42:46anible playbook which will use your an W
  4445. 2:42:50and the command is pretty simple over
  4446. 2:42:51here and I'm just going to explain that
  4447. 2:42:53that command also so this is the anible
  4448. 2:42:55Playbook keyword after that you need to
  4449. 2:42:57supply the anible where you will be
  4450. 2:42:59storing the host second you need to uh
  4451. 2:43:03Supply the name of your anible playbook
  4452. 2:43:05so that is anible Vault Playbook yml
  4453. 2:43:08which you can see over here this is my
  4454. 2:43:09anible playbook VA uh
  4455. 2:43:12yml after that you need to supply the
  4456. 2:43:15path of your anible Vault yml using the
  4457. 2:43:19e keyword okay so this is the path where
  4458. 2:43:22I'm storing my anible VA yml which you
  4459. 2:43:25can find over here also so that's the
  4460. 2:43:27important thing and the third parameter
  4461. 2:43:30which you need to supply over here is
  4462. 2:43:32the ask VA password so that you can key
  4463. 2:43:34in or you can enter the password so that
  4464. 2:43:37that you can open that particular anible
  4465. 2:43:39world and you can use the values or the
  4466. 2:43:41secret value which you have store so
  4467. 2:43:44this is the ncble Playbook command which
  4468. 2:43:45I'm just going to execute from my my
  4469. 2:43:48terminal and then after that we're just
  4470. 2:43:49going to see the value which is printed
  4471. 2:43:51onto the console all right so just copy
  4472. 2:43:54this command from here go to terminal
  4473. 2:43:57I'm just going to clear the screen over
  4474. 2:43:59here and paste the command and hit enter
  4475. 2:44:02and this is the first way of running
  4476. 2:44:04your anible playbook with your ncble
  4477. 2:44:06Vault using the ask Vault parameter so
  4478. 2:44:09this is the parameter which I have just
  4479. 2:44:11applied with your with my ncble playbook
  4480. 2:44:13command okay so I'm just going to key in
  4481. 2:44:16my password and hit enter and here you
  4482. 2:44:19can see this is the message uh this is
  4483. 2:44:21the value which I have printed onto my
  4484. 2:44:23console and it is able to fetch the
  4485. 2:44:25value this is a first uh secret sorry
  4486. 2:44:28there is a typo so this is the first
  4487. 2:44:30secret message from my anible mod so
  4488. 2:44:32this is the text I have stored Inside My
  4489. 2:44:34anible Vault yml and now I'm able to
  4490. 2:44:37fetch that particular information onto
  4491. 2:44:40my console using the debug provided by n
  4492. 2:44:43so this is how I'm just going to use the
  4493. 2:44:45secret value inside my anible playbook
  4494. 2:44:48all right so now you have seen the first
  4495. 2:44:50demo where I have created an anible
  4496. 2:44:52Vault and then I am able to run my
  4497. 2:44:54anible plea book using the ask Vault
  4498. 2:44:57pass parameter where I have key in and
  4499. 2:45:00entered My anible Vault password okay so
  4500. 2:45:03before moving forward let's take a few
  4501. 2:45:05more example of our anible vault command
  4502. 2:45:08so I'm just going to clear the screen
  4503. 2:45:09over here and the second command which I
  4504. 2:45:13would like to tell you is to change the
  4505. 2:45:14password of our anible VA so what you
  4506. 2:45:17need to do over here is you need to key
  4507. 2:45:20in first of all anible Vault after that
  4508. 2:45:24you need to type in the keyword that is
  4509. 2:45:26GRE key and after that you need to
  4510. 2:45:28supply the path of your anible vault yml
  4511. 2:45:31which is groups farar and my vault. yml
  4512. 2:45:34and using this command you can change
  4513. 2:45:36the password of your anible Vault and
  4514. 2:45:38you need you just need to hit enter so
  4515. 2:45:41you need to key in your existing
  4516. 2:45:43password and you can set the new
  4517. 2:45:45password over
  4518. 2:45:47here and you need to reconfirm the
  4519. 2:45:50password and once you use this command
  4520. 2:45:53successfully then you will be able to
  4521. 2:45:55change the password of your anible VA
  4522. 2:45:58yml so this is an useful command when
  4523. 2:46:00you want to change the password uh from
  4524. 2:46:03the security reasons all right so till
  4525. 2:46:05now we have seen like how you can key in
  4526. 2:46:07your ncble Vault password to execute
  4527. 2:46:09your ncble playbook and to use your
  4528. 2:46:11ncble vault in the second example what
  4529. 2:46:15I'm just going to do I'm just going to
  4530. 2:46:16create an password file and and inside
  4531. 2:46:19that password file I'm just going to
  4532. 2:46:20store My anible Vault password and that
  4533. 2:46:23password is not going to be a short
  4534. 2:46:25password but this is going to be my base
  4535. 2:46:2764 randomly generated password and these
  4536. 2:46:31passwords are really long and really
  4537. 2:46:33secure because it is randomly generated
  4538. 2:46:35and those are B 64 password so what I'm
  4539. 2:46:38just going to do I'm just going to first
  4540. 2:46:40of all going to create a b 64 password
  4541. 2:46:43file for my ncble Vault so here inside
  4542. 2:46:46my project there is a directory called
  4543. 2:46:48passor file where I'm just going to
  4544. 2:46:50create a password file right now this
  4545. 2:46:52particular uh directory is empty and if
  4546. 2:46:55you take a look onto the r me file how
  4547. 2:46:57to generate this particular password
  4548. 2:46:59file then this is the third point and
  4549. 2:47:01here I have written the command which is
  4550. 2:47:03op SSL R&D for random and I just want a
  4551. 2:47:06base 64 and 2048 bit and I'm just going
  4552. 2:47:10to create my password file with the name
  4553. 2:47:12n Vault and I'm just going to end it
  4554. 2:47:14with the extension. pass for password
  4555. 2:47:17and it is going to be created in inside
  4556. 2:47:19the directory passor file so I'm just
  4557. 2:47:21going to copy this command from here I'm
  4558. 2:47:23just going to head over to my terminal
  4559. 2:47:25and I'm just going to past the command
  4560. 2:47:26and hit enter and it it will just uh
  4561. 2:47:30complete very silently but what you need
  4562. 2:47:32to do you just need to go over here and
  4563. 2:47:34here you can see this Vault file has
  4564. 2:47:36Vault password file has been created and
  4565. 2:47:38if you double click on it then you can
  4566. 2:47:40see this is a b64 randomly generated uh
  4567. 2:47:43password which we are going which we
  4568. 2:47:45will be using uh to open or to edit our
  4569. 2:47:48n ible VA okay so now we have generated
  4570. 2:47:51our password file now what I need to do
  4571. 2:47:53is I need to create a one more Vault
  4572. 2:47:56using that particular password file so
  4573. 2:47:59this is the command which I'm just going
  4574. 2:48:00to use and this command is again same
  4575. 2:48:02anible Vault create and I'm just going
  4576. 2:48:04to create a new yml for My ncble Vault
  4577. 2:48:07using the name My Vault with b64 pass
  4578. 2:48:11yml and I'm just going to supply the
  4579. 2:48:13password file over here because I'm not
  4580. 2:48:15keying in the password manually or by
  4581. 2:48:18from my keyboard I just want to use my
  4582. 2:48:21existing uh password file which I have
  4583. 2:48:24just generated so here I will just
  4584. 2:48:27Supply the path of that particular
  4585. 2:48:28password file uh to my this anible Vault
  4586. 2:48:32and as you can see in the groups bar uh
  4587. 2:48:34there is only one myor wall. yml and
  4588. 2:48:37that wall. yml is uh like I have entered
  4589. 2:48:41the password manually from the keyboard
  4590. 2:48:44but here uh in the next yml I'm I will
  4591. 2:48:46be using my password file which I have
  4592. 2:48:48just created so I'm just going to copy
  4593. 2:48:49this particular command I'm just going
  4594. 2:48:52to head over to terminal I'm just going
  4595. 2:48:53to clear it and I'm just going to paste
  4596. 2:48:56it and hit enter and as you can see uh
  4597. 2:48:59now I'm into the edit mode and here I
  4598. 2:49:01can create my secret so I'm just going
  4599. 2:49:04to go press I from here and I'm just
  4600. 2:49:06going to type in my secret so let's say
  4601. 2:49:09my uh secret uh uh
  4602. 2:49:13from base
  4603. 2:49:1764 pass
  4604. 2:49:19file so this is the variable and I'm
  4605. 2:49:21just going to key in my text message uh
  4606. 2:49:24text
  4607. 2:49:26message uh from base
  4608. 2:49:3064 I'm just going to type in base 64
  4609. 2:49:34VA and this is just a randomly text
  4610. 2:49:37message I'm just going to key in and
  4611. 2:49:40after that save and
  4612. 2:49:42quit so now what we have done we have
  4613. 2:49:44created a password file and using that
  4614. 2:49:46password file we have created an n fault
  4615. 2:49:50so next thing what I'm just going to do
  4616. 2:49:52I'm just going to use that particular
  4617. 2:49:54debug message inside my ncble fbook to
  4618. 2:49:57print the value of that particular
  4619. 2:49:59variable which I have just created using
  4620. 2:50:01the anible Vault so here's a read me
  4621. 2:50:04file and I'm just going to run my ncble
  4622. 2:50:06playbook but this time I'm just not
  4623. 2:50:08going to enter my password manually but
  4624. 2:50:10I'm just going to use my password file
  4625. 2:50:12to run my anible playbook so this is the
  4626. 2:50:15Playbook command which is anible
  4627. 2:50:17Playbook uh keyword after that you need
  4628. 2:50:19to supply the flag inventory and Supply
  4629. 2:50:21the host file where you are storing the
  4630. 2:50:23host information the name of your
  4631. 2:50:25playbook which is ncble Vault yml and
  4632. 2:50:28after that you need to supply uh the
  4633. 2:50:31Vault file path which is this one which
  4634. 2:50:33is a new one which I have just created
  4635. 2:50:35and after that you need to supply the
  4636. 2:50:37password file over here and you should
  4637. 2:50:39provide the correct path of your
  4638. 2:50:41password file okay so I'm just going to
  4639. 2:50:44copy this command from here go to my
  4640. 2:50:47terminal and and I'm just going to paste
  4641. 2:50:50it over here and hit enter and here you
  4642. 2:50:53can see this is the message which I
  4643. 2:50:55printed onto my console using the debug
  4644. 2:50:58and this is the text message which we
  4645. 2:51:00have just keying in into our new andil
  4646. 2:51:03VA and remember I have not entered My
  4647. 2:51:07anible Vault password manually but
  4648. 2:51:09instead I have just supplied my password
  4649. 2:51:11file as a parameter so this is another
  4650. 2:51:14way to uh like store your password and
  4651. 2:51:17uh into the password file and that
  4652. 2:51:19password file is pretty strong because
  4653. 2:51:21that is a b 64 randomly generated
  4654. 2:51:24password string the third one which we
  4655. 2:51:26going to take a look is to export the
  4656. 2:51:28path of your password file so you have
  4657. 2:51:30already generated a password file but
  4658. 2:51:32what you're going to do you're just
  4659. 2:51:34going to export the path into the
  4660. 2:51:36environment variable and here into the
  4661. 2:51:39readme file you will find the
  4662. 2:51:41environment variable name that is anible
  4663. 2:51:44VA password file so that's the
  4664. 2:51:46particular uh variable name you need to
  4665. 2:51:48keep in and Export into the environment
  4666. 2:51:50variable and once you export into the
  4667. 2:51:52environment variable then you don't need
  4668. 2:51:54to even Supply the path of your password
  4669. 2:51:57file you just simply run your anible
  4670. 2:51:59playbook and anible Playbook will
  4671. 2:52:01resolve that environment variable which
  4672. 2:52:03is this one and it will find the path of
  4673. 2:52:06the password file and it will use that
  4674. 2:52:08password file to supply that password to
  4675. 2:52:10our anible Playbook so which is a more
  4676. 2:52:13neater approach uh while handling your
  4677. 2:52:16anible playbook and anible wallet so in
  4678. 2:52:18this readme file you will find a command
  4679. 2:52:20to export your anible uh password file
  4680. 2:52:23path and here remember this is the
  4681. 2:52:26keyword which you need to keep uh keep
  4682. 2:52:29the same name which is anible Vault
  4683. 2:52:30password file because that is an
  4684. 2:52:32environment variable and after that this
  4685. 2:52:34is the particular path from here uh till
  4686. 2:52:37your password file uh which you can see
  4687. 2:52:39over here so this is the complete
  4688. 2:52:41password file path uh so this path will
  4689. 2:52:44change based on your local workspace
  4690. 2:52:46setup so this is my current workspace
  4691. 2:52:48and this is the current path for my uh
  4692. 2:52:50for my local uh development setup but
  4693. 2:52:53just change this path according to your
  4694. 2:52:55password file path so I'm just going to
  4695. 2:52:57copy this command from here and head
  4696. 2:53:00over to my terminal and I'm just going
  4697. 2:53:02to clear the screen and I'm just going
  4698. 2:53:04to paste the command over here and we
  4699. 2:53:08can also confirm by running the Eco
  4700. 2:53:10dollar and the variable name command so
  4701. 2:53:13that we have exported that particular
  4702. 2:53:15variable successfully or not so here you
  4703. 2:53:17can see the uh environment variable has
  4704. 2:53:19been exported successfully the next
  4705. 2:53:22thing which I'm just going to do I'm
  4706. 2:53:23just going to run my anible playbook and
  4707. 2:53:25this time I'm just not going to supply
  4708. 2:53:28any manual password using the ask B
  4709. 2:53:30password parameter or neither I'm just
  4710. 2:53:32going to supply the password file path
  4711. 2:53:35I'm just going to Simply run my ncble
  4712. 2:53:37playbook so I'm just going to clear the
  4713. 2:53:39screen and I'm just going to paste the
  4714. 2:53:41command over here and if you take a look
  4715. 2:53:43onto the command so this is the command
  4716. 2:53:45uh here I have supplied the inventory
  4717. 2:53:47after that this is The anible Playbook
  4718. 2:53:49command and after that the Vault file
  4719. 2:53:52yml which I'm just going to use it and
  4720. 2:53:54after that I have not specified the ask
  4721. 2:53:56VA password parameter for manually
  4722. 2:53:58entering the password and neither I have
  4723. 2:54:00specified my password file path so I'm
  4724. 2:54:04just going to Simply Supply My Vault so
  4725. 2:54:06that it can understand which Vault I
  4726. 2:54:08want to use and after that I'm just
  4727. 2:54:10going to hit enter and here you can see
  4728. 2:54:13our n Playbook has started and here you
  4729. 2:54:16can see this is the message it has fed
  4730. 2:54:18from from our ncble world so this is
  4731. 2:54:21another way uh to run your ncble
  4732. 2:54:23playbook and to export the path of your
  4733. 2:54:26password file into the environment
  4734. 2:54:28variable so this was a very small
  4735. 2:54:30demonstration on how to use your anible
  4736. 2:54:32Vault inside your anible playbook and
  4737. 2:54:34you can use either of the three ways
  4738. 2:54:36which I have mentioned into this lab
  4739. 2:54:38session uh I'll put down the GitHub
  4740. 2:54:40repository link into the description
  4741. 2:54:42section along with the readme file and
  4742. 2:54:45sometimes I also create a blog post on
  4743. 2:54:46the similar lab session so if you don't
  4744. 2:54:49find these read me file inside the
  4745. 2:54:51GitHub repository then I'll also put the
  4746. 2:54:54blog post link of my blog where I will
  4747. 2:54:56mention all the commands which I have
  4748. 2:54:58used for creating the anible F if you
  4749. 2:55:01have any question or feedback then
  4750. 2:55:02please put down into the comment section
  4751. 2:55:04those are really appreciated and do
  4752. 2:55:06follow this channel for the similar
  4753. 2:55:08content on devops and uh U there are
  4754. 2:55:11many SS I have also planned in future so
  4755. 2:55:14see you into the next session of our
  4756. 2:55:16devop still then take care and bye-bye
  4757. 2:55:19welcome to the last part and in this
  4758. 2:55:21chapter we are going to take a look like
  4759. 2:55:23how I use anible Playbook to deploy my
  4760. 2:55:26own website which is J hook.com here you
  4761. 2:55:28can see this is the blog which I have
  4762. 2:55:30been hosting for a quite some time and
  4763. 2:55:32it is registered on a domain J hook.com
  4764. 2:55:34so this is the blog which I have been
  4765. 2:55:36writing on a various devops topic but
  4766. 2:55:39this particular blog is uh using the
  4767. 2:55:41service provided by a site ground
  4768. 2:55:43hosting so this is the hosting provider
  4769. 2:55:45where I'm hosting my blog so I have
  4770. 2:55:48already purchased this domain and then I
  4771. 2:55:50have registered this domain with this
  4772. 2:55:51site ground hosting provider and here
  4773. 2:55:54you can see this is the dashboard of my
  4774. 2:55:56uh particular blog where I manage the
  4775. 2:55:58deployment of my whole blog before I
  4776. 2:56:00walk you through the various options
  4777. 2:56:02available onto this s ground hosting and
  4778. 2:56:04how I am hosting this blog and how I am
  4779. 2:56:07uploading the files to update my blog
  4780. 2:56:09post it is really important for you to
  4781. 2:56:12understand that how this blog works so
  4782. 2:56:14first of all this blog is not a
  4783. 2:56:17WordPress blog it is a static blog what
  4784. 2:56:19does it mean by a static blog so this
  4785. 2:56:21blog is completely written in markdown
  4786. 2:56:24language as well as the pages which you
  4787. 2:56:26see are just the simple HTML Pages there
  4788. 2:56:29is no database running in the behind the
  4789. 2:56:31scene or in the background so here onto
  4790. 2:56:33the screen you can see this is the
  4791. 2:56:35GitHub repository where my whole blog is
  4792. 2:56:37hosted not hosted but I'm maintaining
  4793. 2:56:39onto my GitHub repository so here you
  4794. 2:56:42will see uh this is the directory uh or
  4795. 2:56:45the directory or the folder which I have
  4796. 2:56:46created onto my GitHub repository and
  4797. 2:56:49there are various options over here but
  4798. 2:56:51I'll walk you through like how I write
  4799. 2:56:53my blog how I test my blog post and how
  4800. 2:56:56I run locally so for that what I use is
  4801. 2:56:59I use Hugo static uh website generator
  4802. 2:57:02so if I go to the Google over here and
  4803. 2:57:05if I search for Hugo static site
  4804. 2:57:10generator then this is the first option
  4805. 2:57:13you will get so this is the framework
  4806. 2:57:15which I'm using this is an open source
  4807. 2:57:17framework which you can install onto
  4808. 2:57:19your local system and you can also start
  4809. 2:57:22uh building your own blogs so this is
  4810. 2:57:24the framework which I'm using uh for my
  4811. 2:57:26own blog development and writing the
  4812. 2:57:29various blog post okay so first thing
  4813. 2:57:31first like how does it work so if you go
  4814. 2:57:34back to the intellig so this is the
  4815. 2:57:36GitHub repository where all of my code
  4816. 2:57:39recites for my blog so what I do
  4817. 2:57:41generally is I just start my Hugo server
  4818. 2:57:44so here if I go to the terminal I'll
  4819. 2:57:46just open in a window mode uh let me
  4820. 2:57:50view mode change it to the Window mode
  4821. 2:57:52okay so I'll just go back to the
  4822. 2:57:53directory and yeah this is the correct
  4823. 2:57:56directory where I'm in right now so the
  4824. 2:57:58command which I use it uh remember you
  4825. 2:58:00need to install the Hugo onto your local
  4826. 2:58:02system to make it work okay so I'm
  4827. 2:58:04assuming that you have already installed
  4828. 2:58:06the Hugo and after that I just simply
  4829. 2:58:08run the command Hugo
  4830. 2:58:10ser and here you can see it is running
  4831. 2:58:13on a local host 13313 port and if I go
  4832. 2:58:16back to my browser and here if I I type
  4833. 2:58:18Local Host 1313 and here you can see uh
  4834. 2:58:21this is the blog uh which is running
  4835. 2:58:23onto my local system so here I make the
  4836. 2:58:26changes I verify the changes and once
  4837. 2:58:28I'm satisfied with my blog post then I
  4838. 2:58:30run the anible Playbook which generally
  4839. 2:58:32copies the HTML to my side ground
  4840. 2:58:35hosting server so that's basic uh thing
  4841. 2:58:38which I do behind the scene when I'm
  4842. 2:58:40writing the various blog post so let's
  4843. 2:58:42start by making a small change first
  4844. 2:58:45local onto our system test that change
  4845. 2:58:47and then we will see how we can use the
  4846. 2:58:49ncble Playbook to deploy this website or
  4847. 2:58:51update this website onto my site site
  4848. 2:58:54ground hosting server okay so here I'll
  4849. 2:58:56go back to my intellig and here are some
  4850. 2:59:00of the directories which I have created
  4851. 2:59:01and I'll just give you a little brief
  4852. 2:59:03about like how I uh structured my uh
  4853. 2:59:06various blog post topic so here you will
  4854. 2:59:08find a Content directory and in the
  4855. 2:59:10content directory you will find a post
  4856. 2:59:12directory and inside the post I have
  4857. 2:59:14created a various directory where I keep
  4858. 2:59:16on writing the various blog posts so for
  4859. 2:59:18example anible AWS devop stalker GitHub
  4860. 2:59:22so these are the various categorization
  4861. 2:59:24which I have done so let's take a look
  4862. 2:59:26onto the nple because the latest post
  4863. 2:59:28which I see is this one which I have
  4864. 2:59:30written on September 19th last year I
  4865. 2:59:32have not been active on this blog but
  4866. 2:59:35let's take a look uh so here this is the
  4867. 2:59:37uh markdown file which I generally
  4868. 2:59:39create for my writing my blog so uh this
  4869. 2:59:42is a markdown uh structure which you
  4870. 2:59:45need to follow for writing this blog
  4871. 2:59:47post I I know it it might look
  4872. 2:59:49complicated for you but if once you get
  4873. 2:59:51familiar with using the markdown then
  4874. 2:59:53it's really easy to manage your blog
  4875. 2:59:55post and you can write it from anywhere
  4876. 2:59:57and you don't need any Hy fancy tool to
  4877. 3:00:00manage your blog you just need a editor
  4878. 3:00:02I'm using intellig you can use Sublime
  4879. 3:00:04notepad++ and you can manage your blog
  4880. 3:00:08anyway so what I'm just going to do over
  4881. 3:00:10here is I'm just going to change a few
  4882. 3:00:11things over here so let's see n Handler
  4883. 3:00:14example real world use case and example
  4884. 3:00:17so here I will remove the question mark
  4885. 3:00:19I'll save it and last modify so I'll
  4886. 3:00:22change the state uh I'll change it to
  4887. 3:00:24something uh let's say
  4888. 3:00:2724 and make it March and uh make it
  4889. 3:00:31let's say what's the date today 6th of
  4890. 3:00:34March okay and I think U that's the
  4891. 3:00:38small change which I have done it so
  4892. 3:00:40let's save this file and go back to your
  4893. 3:00:42browser just refresh it and here you can
  4894. 3:00:44see this question mark is gone from here
  4895. 3:00:46if you click on this block post and here
  4896. 3:00:48you can see the last modified date has
  4897. 3:00:50been updated to 6th of March okay so
  4898. 3:00:53this is the modification we have done
  4899. 3:00:55and we are able to verify this change
  4900. 3:00:58okay now the next thing is I'll show you
  4901. 3:01:00how I generate the HTML file and here
  4902. 3:01:03you can see this whole uh block post is
  4903. 3:01:06still into markdown file which you can
  4904. 3:01:08see it is ending with the file. MD which
  4905. 3:01:11is a markdown extension so using this uh
  4906. 3:01:14markdown file we are just going to
  4907. 3:01:16generate an HTML page and that HTML page
  4908. 3:01:19we are just going to copy it to the site
  4909. 3:01:21ground server now how to generate the
  4910. 3:01:23HTML page using the markdown which I
  4911. 3:01:26have just updated so for that we are
  4912. 3:01:28going to use the Hugo command utility
  4913. 3:01:30because I have already shown you like I
  4914. 3:01:32have already installed the Hugo onto my
  4915. 3:01:34local system so here onto the terminal
  4916. 3:01:37what I'll do I'll just go I'll clear the
  4917. 3:01:39screen over here and first thing the uh
  4918. 3:01:42whenever I generate the HTML file then
  4919. 3:01:45it will generate a public folder over
  4920. 3:01:47here so here you can see there is no
  4921. 3:01:49public folder which you can see and in
  4922. 3:01:50that public folder it is going to
  4923. 3:01:52generate all the HTML file after passing
  4924. 3:01:55the markdown file okay so let's go back
  4925. 3:01:58over here uh onto my terminal I'll just
  4926. 3:02:01open the terminal over here and you just
  4927. 3:02:03need to run the command Hugo and it will
  4928. 3:02:06automatically read the all the
  4929. 3:02:08directories where markdown file is
  4930. 3:02:10present and then it is going to process
  4931. 3:02:12it and generate the static HTML file for
  4932. 3:02:14me so here you can see this is the
  4933. 3:02:16output and it has processed so many
  4934. 3:02:19files and these are the images because I
  4935. 3:02:21have copy pasted uh some of the images
  4936. 3:02:24into my blog post as well so these are
  4937. 3:02:25the stats which it has passed and here
  4938. 3:02:29you can see there are 295 Pages which
  4939. 3:02:31has passed and if you go over here then
  4940. 3:02:34you will see a public file over here
  4941. 3:02:36public folder over here and inside this
  4942. 3:02:38public folder you will file all find all
  4943. 3:02:40the HTML for all the blog post so here
  4944. 3:02:43you can see this is a really long list
  4945. 3:02:45because I have posted quite a lot of
  4946. 3:02:47post onto my my blog so all the pages
  4947. 3:02:49are all available over here and if you
  4948. 3:02:51open any of the page let's say I open
  4949. 3:02:54this one then you will see a index.html
  4950. 3:02:57page and if you'll open this one then
  4951. 3:02:59you will find all the blog post in the
  4952. 3:03:01form of HTML so this is how I write my
  4953. 3:03:05markdown uh blog post and then I
  4954. 3:03:07generate the HTML page so this is the
  4955. 3:03:10basic setup for my uh blog and this is
  4956. 3:03:13how I write and generate the HTML in the
  4957. 3:03:16next uh step we are going to take a look
  4958. 3:03:18like how I have written my anible
  4959. 3:03:21playbook to copy this HTML this public
  4960. 3:03:23folder to my site ground hosting server
  4961. 3:03:26okay so let's recap so here is my laptop
  4962. 3:03:29here I have writing the markdown file
  4963. 3:03:32and which markdown file I'm paring using
  4964. 3:03:34the Hugo and Hugo is generating me the
  4965. 3:03:36HTML pages so that's a very basic setup
  4966. 3:03:39which I have onto my local laptop now
  4967. 3:03:42the next thing is how to copy that
  4968. 3:03:44particular file to uh my remote server
  4969. 3:03:47which which is a static ground uh static
  4970. 3:03:49ground uh hosting server so here you can
  4971. 3:03:52see this is my laptop on the left hand
  4972. 3:03:54side which has a private key so I need
  4973. 3:03:57to generate uh as such key one is the
  4974. 3:04:00private key and one is the public key so
  4975. 3:04:03I'm just going to generate that key I'm
  4976. 3:04:05just going to keep the private key on my
  4977. 3:04:07laptop and the public key I'm just going
  4978. 3:04:09to keep onto my site ground server I'm
  4979. 3:04:12just going to show you how to generate
  4980. 3:04:13that key but just understand this
  4981. 3:04:15concept so here I will keep the private
  4982. 3:04:17key with key with me that is only
  4983. 3:04:19available for me and the public key onto
  4984. 3:04:21my side ground server and after that we
  4985. 3:04:24are going to use this SSH key uh to
  4986. 3:04:27communicate with my side ground server
  4987. 3:04:29and using this private key I'm just
  4988. 3:04:31going to copy the HTML file inside my
  4989. 3:04:34site ground hosting server and those
  4990. 3:04:36files are going to be my HTML file which
  4991. 3:04:39I have just generated now let's take a
  4992. 3:04:41look onto to the site ground and how the
  4993. 3:04:43files are visible over there so if I go
  4994. 3:04:45to my browser over here go to the site
  4995. 3:04:48ground so this is my console of my
  4996. 3:04:50website where I'm hosting my website so
  4997. 3:04:53here you just need to go to site over
  4998. 3:04:55here and here you will find a file
  4999. 3:04:58manager so here in the file manager you
  5000. 3:05:00will find uh the public HTML directory
  5001. 3:05:04which you can see and here in the
  5002. 3:05:05public. HTML you will find all the HTML
  5003. 3:05:08pages so if I open this one and here you
  5004. 3:05:12can see the index.html page so these are
  5005. 3:05:14the files which I generally copy from my
  5006. 3:05:17local machine to my site ground hosting
  5007. 3:05:20server okay but how do I do that so what
  5008. 3:05:23I do is like this is a flow which I have
  5009. 3:05:26implemented using the N so I hope now
  5010. 3:05:29the SSH key part is clear to you I'm
  5011. 3:05:32copying HTML file from my local laptop
  5012. 3:05:34to my site ground hosting server okay so
  5013. 3:05:37this is the part I hope you're clear
  5014. 3:05:39with that the next thing is how I'm
  5015. 3:05:41copying this file I'm not copying one
  5016. 3:05:44file by one file I'm just generating the
  5017. 3:05:47file then I'm creating a z file then I'm
  5018. 3:05:49uploading the zip file to the side
  5019. 3:05:51ground server which I'm just going to
  5020. 3:05:52show to you so this is my laptop here
  5021. 3:05:55I'm generating the HTML file after that
  5022. 3:05:57I'm creating a zif file and that zip
  5023. 3:06:00file I'm just putting it onto or I'm
  5024. 3:06:02uploading it onto my S ground hosting
  5025. 3:06:04server and once I upload that Zev file
  5026. 3:06:06then I'm just going to extract again all
  5027. 3:06:09the HTML files out of it and this is how
  5028. 3:06:12I do the deployment of my website onto
  5029. 3:06:14the site ground using the N Okay so that
  5030. 3:06:17part is clear to you now coming back to
  5031. 3:06:20the point I need SSH keys I need a
  5032. 3:06:23private key and I need a public key so
  5033. 3:06:25that our whole uh uh communication is
  5034. 3:06:28secured between the side ground on my
  5035. 3:06:30and also my laptop okay so I'm just
  5036. 3:06:32going to open the terminal over here so
  5037. 3:06:35let's open the terminal over here and in
  5038. 3:06:38the terminal you can just type the
  5039. 3:06:39command SSH key gen and it will generate
  5040. 3:06:43the public key and the private key for
  5041. 3:06:44you so here as soon as you enter the SS
  5042. 3:06:47keys in onto your terminal if you're
  5043. 3:06:50using the Windows system then I would
  5044. 3:06:52highly recommend to use git bash because
  5045. 3:06:54that's where you can run these command
  5046. 3:06:56or you can use the wsl2 which is like a
  5047. 3:07:00uh sub Linux subsystem which you can
  5048. 3:07:02install onto to your laptop uh if you're
  5049. 3:07:05using the windows so I would highly
  5050. 3:07:07recommend to use those so that you can
  5051. 3:07:09generate the SSH keyen I'm using the uh
  5052. 3:07:12Mac so here I have the terminal so here
  5053. 3:07:14I can run these kind of a command so it
  5054. 3:07:16will generate the key onto this
  5055. 3:07:18particular directory so keep in mind uh
  5056. 3:07:20just always remember this is the path
  5057. 3:07:22where you will get the keys okay so what
  5058. 3:07:25I'm just going to do I'm just going to
  5059. 3:07:27copy this full path and I'm just going
  5060. 3:07:29to put some custom name to my key so I'm
  5061. 3:07:32just going to paste it over here and I'm
  5062. 3:07:34just going to put site uh ground uh demo
  5063. 3:07:39okay and hit enter uh do you like to
  5064. 3:07:42have a pass phras for your SSH key then
  5065. 3:07:45I'm just I'm just going to skip that one
  5066. 3:07:46no I'm just going to Simply hit enter
  5067. 3:07:49okay and now my keys are generated so if
  5068. 3:07:52I go to this particular directory and if
  5069. 3:07:55I run the ls command so I'm just going
  5070. 3:07:57to copy this path clear the path and I'm
  5071. 3:08:01just going to run the command LT and I'm
  5072. 3:08:04just going to paste the
  5073. 3:08:06path so here you can see this is
  5074. 3:08:09our private key and this is Pub is going
  5075. 3:08:13to be our public key so this is how
  5076. 3:08:16you're just going to generate the keys
  5077. 3:08:18for you and these Keys we are going to
  5078. 3:08:21use to upload our HTML Z file okay I
  5079. 3:08:25just wanted to show you the key because
  5080. 3:08:27the keys I have already generated and I
  5081. 3:08:29have already set up for my site ground
  5082. 3:08:31hosting so I'm not going to change those
  5083. 3:08:33thing but all the steps which I'm
  5084. 3:08:36showing to you is exactly the same this
  5085. 3:08:37is how you just going to generate the
  5086. 3:08:39key and then we are going to use those
  5087. 3:08:41keys to uh enable the communication
  5088. 3:08:43between the server and our lab okay so
  5089. 3:08:45now let's talk like where I have
  5090. 3:08:47configured the public key onto my side
  5091. 3:08:50ground server so here you can see this
  5092. 3:08:51is the public key which is I have put it
  5093. 3:08:54mentioned over here so I need to set up
  5094. 3:08:56that particular key so if you go to my
  5095. 3:08:58site ground hosting go to dashboard and
  5096. 3:09:02here if you go to the tools I'm saying
  5097. 3:09:05it should be security and here you can
  5098. 3:09:08see this is a security go to SSL
  5099. 3:09:11manager and uh in the SSL manager U wait
  5100. 3:09:15for a second sorry it's under Dev
  5101. 3:09:19and here you will find the SSH key
  5102. 3:09:21manager so in this section you will find
  5103. 3:09:23the keys so here you can see uh here I
  5104. 3:09:26have already uh uploaded this key this
  5105. 3:09:28is our SSH RSA key so this key I have
  5106. 3:09:32already uploaded over here so this is my
  5107. 3:09:35public key which I have just uploaded to
  5108. 3:09:37the site ground and there are few more
  5109. 3:09:40details which you need to keep in mind
  5110. 3:09:42so this is the username uh because you
  5111. 3:09:46have the key but you need a username to
  5112. 3:09:48login into your uh site ground server so
  5113. 3:09:51here I'm this is the username for that
  5114. 3:09:54Linux system and this is the port where
  5115. 3:09:56I will be doing the communication or
  5116. 3:09:58this port is open for performing this
  5117. 3:10:00kind of activity since I'm using sround
  5118. 3:10:03so it is very specific to site ground
  5119. 3:10:06but if you're using any other Linux
  5120. 3:10:08server or Linux hosting then you should
  5121. 3:10:10get a username something from that Linux
  5122. 3:10:13hosting and you should check the port
  5123. 3:10:15number which they are allowing you to
  5124. 3:10:17use so these are the few details which
  5125. 3:10:19you need to keep in mind okay and uh
  5126. 3:10:22this key SSH Keys concept is pretty much
  5127. 3:10:25common irrespective of any of the
  5128. 3:10:28hosting Services you are using so just
  5129. 3:10:30check with them like do they support or
  5130. 3:10:32do they have this feature enabled for
  5131. 3:10:34you or not if they have enabled it then
  5132. 3:10:36just simply upload the public key over
  5133. 3:10:38here okay and how to do that sometime
  5134. 3:10:42you can even import the key so you just
  5135. 3:10:44need to paste the content over here so
  5136. 3:10:46if you see over here
  5137. 3:10:49um so here if I clear this directory and
  5138. 3:10:53if I go over here and I type site ground
  5139. 3:10:56demo. Pub so uh not lslt it should be
  5140. 3:11:01cat
  5141. 3:11:03actually and here you can see you can
  5142. 3:11:05just simply copy this content from
  5143. 3:11:09here and go to your site ground hosting
  5144. 3:11:12and paste it over here it is that simple
  5145. 3:11:15so you have just uploaded the public key
  5146. 3:11:17onto your whatever hosting you're using
  5147. 3:11:20so this is that simple okay so now uh
  5148. 3:11:23this is our SSH key manager I'm not
  5149. 3:11:25going to use this one and here we
  5150. 3:11:27already have those keys with us okay now
  5151. 3:11:30I have explained you the whole setup and
  5152. 3:11:32how we are going to implement these
  5153. 3:11:34things and what are the prerequisites
  5154. 3:11:36which is needed to achieve this thing so
  5155. 3:11:39now I will explain to you like how I
  5156. 3:11:41have written the anible Playbook to
  5157. 3:11:43implement the whole scenario okay so in
  5158. 3:11:45the same uh reposit itory where I'm
  5159. 3:11:48having my blog uh I have created anible
  5160. 3:11:51Playbook directory and here in the
  5161. 3:11:53anible Playbook I have created a J hook
  5162. 3:11:55Playbook yml okay so this is the task
  5163. 3:11:58which I have created and the task I have
  5164. 3:12:00created a role which is Jook So if you
  5165. 3:12:02go over here and one more thing I
  5166. 3:12:04mentioned the username so I'm using this
  5167. 3:12:06username if you take a look this is the
  5168. 3:12:08username and if you go back then you
  5169. 3:12:11will find the same username over here
  5170. 3:12:13which is this one so that's why I said
  5171. 3:12:15like you just need to check with them
  5172. 3:12:16like what kind of a username they are
  5173. 3:12:18allowing you to use so this is the
  5174. 3:12:20username which I'm using so I'm running
  5175. 3:12:22this whole Playbook with this particular
  5176. 3:12:24remote user and this is the task which I
  5177. 3:12:26have created so let's take a look onto
  5178. 3:12:28the task so this is the J hook uh go to
  5179. 3:12:31inventory not inventory go to roles go
  5180. 3:12:34to Jook go to task and there is a main.
  5181. 3:12:37yml okay so this is the U main Playbook
  5182. 3:12:40which is responsible for copying the
  5183. 3:12:43content all right so first thing uh this
  5184. 3:12:47is the simple task which is just
  5185. 3:12:49outputting the path which is PWD the
  5186. 3:12:51current
  5187. 3:12:53path second it is running the Hugo
  5188. 3:12:55command it is just a simple Hugo command
  5189. 3:12:57to generate the HTML content so if I uh
  5190. 3:13:02if you remember then I have shown you
  5191. 3:13:04like this is the command which I have
  5192. 3:13:05run previously so this is the Hugo
  5193. 3:13:07command which I have run so which has
  5194. 3:13:09generated the basic HTML Pages for us in
  5195. 3:13:13the public directory which is uh
  5196. 3:13:17this one where it is this one okay so
  5197. 3:13:20I'm just simply running the Hugo command
  5198. 3:13:22so that I can generate the HTML Pages
  5199. 3:13:24for my block posts after that uh this is
  5200. 3:13:29simple debug I have written just for
  5201. 3:13:30debugging whether it is on a correct
  5202. 3:13:33path or not second here I'm running the
  5203. 3:13:36command to compress the directory so I
  5204. 3:13:39just wanted to compress the public
  5205. 3:13:41directory which is this directory so
  5206. 3:13:44here this is the path of that uh sorry
  5207. 3:13:47this is just a name but here I'm just
  5208. 3:13:49putting the path so this is the path so
  5209. 3:13:51this is the project path and if you can
  5210. 3:13:53see this variable so this variable I
  5211. 3:13:55have defined into roles and if you go to
  5212. 3:13:58vs and this is the main do VAR so this
  5213. 3:14:00is the project path I'll just go to I'll
  5214. 3:14:03just wrap it
  5215. 3:14:05around and here you can see this is the
  5216. 3:14:07uh location where my current project is
  5217. 3:14:10available onto my Mech uh laptop so this
  5218. 3:14:14is the exact path where my uh files are
  5219. 3:14:16located
  5220. 3:14:17so this is using the project path and
  5221. 3:14:19there it is looking for a public
  5222. 3:14:21directory and then it is looking for all
  5223. 3:14:22the content and in the destination it is
  5224. 3:14:25again using the same project path and
  5225. 3:14:27here it is creating a zip file name and
  5226. 3:14:30what is the zip file name variable it is
  5227. 3:14:31jhop do zip okay so here you can see uh
  5228. 3:14:35we have the public directory but I have
  5229. 3:14:37not run the Playbook so there is no zip
  5230. 3:14:40uh J hook. up which has been created
  5231. 3:14:42I'll show you once I run this Playbook
  5232. 3:14:44okay so here uh
  5233. 3:14:47here till this part we are just creating
  5234. 3:14:49the Z file so if you take a look onto
  5235. 3:14:52our presentation once again so here uh
  5236. 3:14:56HTML has been generated and now we have
  5237. 3:14:58created a zip using the zip uh anible
  5238. 3:15:01task okay uh here so we have completed
  5239. 3:15:05this many task next we are just doing
  5240. 3:15:08the copy operation so here it is using
  5241. 3:15:11the path like project path and the zip
  5242. 3:15:14file name which is this one okay so it
  5243. 3:15:17is using this complete Z file and it is
  5244. 3:15:20uploading it to the J hook.com which is
  5245. 3:15:22our site ground hosting and this is the
  5246. 3:15:24destination directory okay and here is
  5247. 3:15:26the destination directory which I have
  5248. 3:15:27defined so if you go to over here and
  5249. 3:15:30this is the destination directory so
  5250. 3:15:31which you can see which is home this is
  5251. 3:15:34the username uh of my site ground
  5252. 3:15:37hosting and this is the path which is J
  5253. 3:15:40hook.com picore HTML and if I show you
  5254. 3:15:43over here then if I go
  5255. 3:15:47uh to file manager and if I go here you
  5256. 3:15:51can see this is the path actually I'm
  5257. 3:15:54inside if you go here then here you can
  5258. 3:15:56see this is the path which is uh where I
  5259. 3:15:58need to upload it job.com public HTML
  5260. 3:16:02and which
  5261. 3:16:03is this
  5262. 3:16:05one exactly okay and let's go back to
  5263. 3:16:10the task uh task yml once again and
  5264. 3:16:13after that I'm just after copying that
  5265. 3:16:16particular file
  5266. 3:16:17uh if I take a look over here so here I
  5267. 3:16:20just copied it the zip file over there
  5268. 3:16:22after that I have written extract task
  5269. 3:16:25so this is going to extract that
  5270. 3:16:27particular Z file so here it is just
  5271. 3:16:29going to extract and generate or uh
  5272. 3:16:32extract the HTML file out of the C file
  5273. 3:16:35and here this is the task which I have
  5274. 3:16:37written for that one and once it is
  5275. 3:16:39extracted then it is going to remove
  5276. 3:16:41that particular Z file then this Z file
  5277. 3:16:44from the remote server is going to
  5278. 3:16:46remove so this is the simple Playbook
  5279. 3:16:48which I have written to automate the
  5280. 3:16:51deployment of my blog post onto uh my
  5281. 3:16:55site ground hosting and one key thing uh
  5282. 3:16:58I forgot to tell you like where is my
  5283. 3:17:00private key I have shown you like how to
  5284. 3:17:02upload the public key to the sideg
  5285. 3:17:04ground hosting but where is my private
  5286. 3:17:06key so in the same anible Playbook
  5287. 3:17:08directory in the inventory you will find
  5288. 3:17:11I have used this private key which is J
  5289. 3:17:14hook this is our private key which is
  5290. 3:17:16I'm only keeping it over here although I
  5291. 3:17:18have copied this public key also but I'm
  5292. 3:17:21not I'm not using this public key
  5293. 3:17:23anywhere I just copied it so that if I
  5294. 3:17:26uh if I change my laptop if I format my
  5295. 3:17:29laptop then I have a copy of that
  5296. 3:17:31particular key I don't need to
  5297. 3:17:33regenerate that key so that's the
  5298. 3:17:35purpose I have kept it over there and in
  5299. 3:17:37the host file if you take a look uh if I
  5300. 3:17:41go and show you once again so this is
  5301. 3:17:43the uh sorry it should be it should be J
  5302. 3:17:46hook uh I have just changed the host
  5303. 3:17:48name so here is the name of my Host this
  5304. 3:17:52is the uh path of my private file and
  5305. 3:17:56this is the port where it will be
  5306. 3:17:58communicating okay so this is the host
  5307. 3:18:01which is side ground Host this is the
  5308. 3:18:03path of my private file a private SSH
  5309. 3:18:06key and this is the port where it will
  5310. 3:18:08do the communication so this is the
  5311. 3:18:10defination or this is the configuration
  5312. 3:18:12for my host file for running this
  5313. 3:18:15anible okay
  5314. 3:18:17now we have seen everything now we need
  5315. 3:18:19to run this Playbook okay and if I go
  5316. 3:18:23back to my website uh refresh this page
  5317. 3:18:26over here and here you can see this uh
  5318. 3:18:29uh question mark is still there and if
  5319. 3:18:31we check the last modified that then it
  5320. 3:18:34is 19th September
  5321. 3:18:362023 okay but on local if you check the
  5322. 3:18:39same thing then it is there is no
  5323. 3:18:41question mark and the modified date is
  5324. 3:18:436th of March okay so let's update the
  5325. 3:18:46whole uh let's run the Playbook and
  5326. 3:18:48update the whole uh block post okay go
  5327. 3:18:51back to your uh terminal over here in
  5328. 3:18:54the ID and uh go I'll clear this
  5329. 3:18:59[Music]
  5330. 3:19:00one then I'll go to the anible directory
  5331. 3:19:04and here what I do is I generally uh
  5332. 3:19:06written the command into that yml so
  5333. 3:19:08which is jhub dot this is the Playbook
  5334. 3:19:11command which I generally run so this
  5335. 3:19:13I'll just copy this command I'm just
  5336. 3:19:15going to explain to you also that
  5337. 3:19:17one and I'm just going to paste it so
  5338. 3:19:21this is the simple command which is n
  5339. 3:19:23Playbook then there is a inventory and
  5340. 3:19:25inventory I'm specifying the host file
  5341. 3:19:27the host location of the file and the
  5342. 3:19:29name of the Playbook which I'm just
  5343. 3:19:31running which I have just explain to you
  5344. 3:19:33okay it is that simple and after that
  5345. 3:19:35you just simply hit
  5346. 3:19:38enter and here you can see it started to
  5347. 3:19:42uh create uh the public HTML that it is
  5348. 3:19:45going to now it is compressed in the
  5349. 3:19:47file now it is copying the content to
  5350. 3:19:50side
  5351. 3:19:54ground and this is the
  5352. 3:19:57host and now it is extracting the zip
  5353. 3:20:00file onto the side ground at this
  5354. 3:20:02particular
  5355. 3:20:03location and after that it is removing
  5356. 3:20:07this particular Z file over here so it
  5357. 3:20:09has finished this task okay and if you
  5358. 3:20:12take a look over here then here you can
  5359. 3:20:14see now the Z.Z file has been created
  5360. 3:20:17over here okay which was not present
  5361. 3:20:20previously so now my content is updated
  5362. 3:20:23onto my website so if you go back over
  5363. 3:20:27here uh and I'll close this Local Host
  5364. 3:20:30if you see take a look this is Local
  5365. 3:20:31Host I'm just going to close this one
  5366. 3:20:33I'll just close this one also and I'll
  5367. 3:20:36just go to the dashboard and over here
  5368. 3:20:39so if I refresh this page uh right now
  5369. 3:20:42so it will not show the changes because
  5370. 3:20:44there are some caching which is
  5371. 3:20:46implemented from side ground so I need
  5372. 3:20:48to delete the whole caching for my
  5373. 3:20:50website so that it can show the latest
  5374. 3:20:52changes okay so I'll go to the site
  5375. 3:20:55ground and uh I think it should be into
  5376. 3:20:58the speed go to
  5377. 3:21:01caching go to Dynamic caching and then
  5378. 3:21:04clean this flush the
  5379. 3:21:06cachier and now the cachier has been
  5380. 3:21:08flushed so these are some custom
  5381. 3:21:11settings which I learned eventually when
  5382. 3:21:13I started working more with my blog post
  5383. 3:21:15and hosting uh uh side ground
  5384. 3:21:18hosting now uh the caching has been
  5385. 3:21:21cleaned and I'll just refresh this page
  5386. 3:21:23once again and here you can see the
  5387. 3:21:25question mark is gone and the last
  5388. 3:21:27modified date it shows now the 6th of
  5389. 3:21:29March so this is how I maintain my blog
  5390. 3:21:34post and this is how I uh automated my
  5391. 3:21:37whole deployment because uh what happens
  5392. 3:21:40is like I generally write quite a lot of
  5393. 3:21:43blog post and I modify quite a lot of
  5394. 3:21:45blog post so it's a quite manual thing
  5395. 3:21:47if I write a four or five blog post and
  5396. 3:21:49those blog post has certain images so a
  5397. 3:21:53single blos block post update can
  5398. 3:21:55contains four or five images four or
  5399. 3:21:58five files so I just need to manually
  5400. 3:22:01copy those files if I don't use anible
  5401. 3:22:04so instead of uh doing that task
  5402. 3:22:06manually I just return this anible
  5403. 3:22:08Playbook which just generate everything
  5404. 3:22:11zip it everything and upload it to the
  5405. 3:22:13server and that's how I just automated
  5406. 3:22:16this task and it just take a few clicks
  5407. 3:22:17to run the Playbook and my blog is up to
  5408. 3:22:20dat I hope this uh project will help you
  5409. 3:22:23to understand uh the previous concept
  5410. 3:22:26which you have learned throughout in
  5411. 3:22:27this course and you got a chance to see
  5412. 3:22:30like how I'm using it in a real time so
  5413. 3:22:33if you like this kind of a Content
  5414. 3:22:35that's please considering subscribing to
  5415. 3:22:37this Channel and also please check out
  5416. 3:22:39the premium membership program also
  5417. 3:22:41which I have just created for you where
  5418. 3:22:44I keep on uploading these kind of
  5419. 3:22:45projects over there as well so keep
  5420. 3:22:48following this channel for more devops
  5421. 3:22:50related topics and see you into the next
  5422. 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.