1 00:00:00,640 --> 00:00:07,090 In this video, we are going to check a file or a directory status that whether that file or directory 2 00:00:07,090 --> 00:00:11,740 exists and what are the attributes associated with the file. 3 00:00:11,830 --> 00:00:19,540 So the very first thing is we will go into our control node and we will create a new YAML file, we'll 4 00:00:19,540 --> 00:00:24,100 name it check fs fs for file status YAML file. 5 00:00:25,040 --> 00:00:25,540 Okay. 6 00:00:25,550 --> 00:00:30,490 And let's see how we are going to define our YAML file. 7 00:00:30,500 --> 00:00:32,030 What are the things we need to write it? 8 00:00:32,030 --> 00:00:38,060 So first thing is we need to define that it's a GMO file and then we have to put in dash, dash, dash, 9 00:00:38,060 --> 00:00:41,900 then the name of the entire Playbook file status module. 10 00:00:41,900 --> 00:00:44,270 Of course you could name it anything that you want. 11 00:00:44,510 --> 00:00:48,470 The Host Where is it going to run it against? 12 00:00:48,620 --> 00:00:50,390 It's going to run at this time. 13 00:00:50,390 --> 00:00:52,010 We'll run it against our local host. 14 00:00:52,010 --> 00:00:53,780 You can put it all as well. 15 00:00:53,780 --> 00:01:01,580 And as you know, when you put all, it will go to your host file, which is at sea as well, host file 16 00:01:01,580 --> 00:01:03,530 and whatever you have defined in that host. 17 00:01:03,530 --> 00:01:06,620 Well, it will run it against those clients. 18 00:01:06,920 --> 00:01:07,520 All right. 19 00:01:07,520 --> 00:01:11,030 Moving down task, what do you want to run? 20 00:01:11,120 --> 00:01:18,680 The name of the task is check, file, status and attributes and the module that we will use to check 21 00:01:18,680 --> 00:01:21,140 that it's called STAT. 22 00:01:21,800 --> 00:01:22,340 All right. 23 00:01:22,340 --> 00:01:24,800 So this is the stat module. 24 00:01:24,800 --> 00:01:26,690 And now where is the path? 25 00:01:26,690 --> 00:01:29,870 Where is the path of that file or directory? 26 00:01:29,870 --> 00:01:32,420 So we'll define path and path at see. 27 00:01:32,450 --> 00:01:34,520 Host It's just a random file that I picked. 28 00:01:34,520 --> 00:01:36,980 You could pick anyone where you're running your check against. 29 00:01:37,430 --> 00:01:39,290 All right, so this is the location. 30 00:01:39,290 --> 00:01:43,010 And then you have to specify the registration. 31 00:01:43,010 --> 00:01:49,730 Like once the result comes back, you have to hold it somewhere because you cannot just put a stat module 32 00:01:49,730 --> 00:01:52,880 and it will check the status and show it on your screen. 33 00:01:52,880 --> 00:01:59,570 So in order to print that on your screen, you have to use the message, the debug module. 34 00:01:59,780 --> 00:02:08,120 So the first thing is registered, put that output that you get from the stat into some kind of container 35 00:02:08,510 --> 00:02:13,370 and we are registering that or outputting that to an RFS container. 36 00:02:13,640 --> 00:02:16,430 I just picked this a two letter word. 37 00:02:16,430 --> 00:02:19,490 You could pick any word you of your choice. 38 00:02:19,910 --> 00:02:24,800 So then we will use this debug module. 39 00:02:24,800 --> 00:02:26,900 So again we'll specify the name. 40 00:02:26,900 --> 00:02:35,150 Now show result since you already did the stat on that Etsy host and we put it into the FS container 41 00:02:35,150 --> 00:02:42,080 now show that FS container so we'll use debug module and the debug module will have this is the module 42 00:02:42,080 --> 00:02:50,000 to print and the message will be file attributes and then we are going to show the result of our FS 43 00:02:50,000 --> 00:02:50,720 container. 44 00:02:51,290 --> 00:02:51,680 All right. 45 00:02:51,680 --> 00:02:58,430 And then basically we'll run the playbook and the playbook, as you know, the command will be Ansible 46 00:02:58,430 --> 00:03:04,490 Dash Playbook space, the name of your YAML file or the playbook. 47 00:03:05,000 --> 00:03:12,770 All right, so let's go to our control node and let's run this playbook or let's create this playbook. 48 00:03:13,220 --> 00:03:16,670 So I have my node right here. 49 00:03:17,630 --> 00:03:19,640 I'm going to log in as root. 50 00:03:20,450 --> 00:03:20,900 All right. 51 00:03:20,900 --> 00:03:25,040 I am an etsy sorry slash home directory. 52 00:03:25,040 --> 00:03:27,440 I am logged in as who? 53 00:03:28,150 --> 00:03:30,160 I am I am logged in as root. 54 00:03:30,220 --> 00:03:30,480 Okay. 55 00:03:30,520 --> 00:03:34,650 So I'll go into Etsy and Sybil playbook. 56 00:03:34,660 --> 00:03:38,200 That's where I'm keeping all my playbooks. 57 00:03:38,740 --> 00:03:39,200 All right. 58 00:03:39,220 --> 00:03:39,790 Here. 59 00:03:39,790 --> 00:03:46,710 I have already created this checked fs yaml file so we could save some time. 60 00:03:46,720 --> 00:03:50,110 So you could write as I have written here. 61 00:03:50,110 --> 00:03:57,610 Or you could get that file which I have already uploaded in the in the handouts. 62 00:03:58,000 --> 00:04:06,130 So anyway, so let me go over them that check fs yaml and you'll see right here. 63 00:04:06,130 --> 00:04:13,420 The very first thing is we define that it's a YAML file dash, dash, dash name or run stat module or 64 00:04:13,420 --> 00:04:18,640 files that module host we are running it against a local host. 65 00:04:18,850 --> 00:04:26,500 Then the tasks just like the what I have on the PowerPoint slide, the name check file status and attributes. 66 00:04:26,590 --> 00:04:27,040 All right. 67 00:04:27,040 --> 00:04:33,830 And the module you're using, it's a stat module just like we have a copy module, move module just 68 00:04:33,850 --> 00:04:36,580 to check the status of a file attributes. 69 00:04:36,670 --> 00:04:39,310 We use this stat our path, of course. 70 00:04:39,310 --> 00:04:41,980 Where is that file that you want to stat? 71 00:04:42,310 --> 00:04:49,480 And once the result comes back, we are going to register that or put that result into as a temporary 72 00:04:49,480 --> 00:04:50,200 container. 73 00:04:50,200 --> 00:04:53,980 And for that we have to use it register parameters. 74 00:04:54,010 --> 00:04:54,370 All right. 75 00:04:54,370 --> 00:05:03,190 And we are defining that variable or that container is FS are I then show values or show result doesn't 76 00:05:03,190 --> 00:05:04,450 matter what you choose. 77 00:05:04,450 --> 00:05:10,660 The debug is the module and the message file attributes and then read that container. 78 00:05:11,290 --> 00:05:12,760 All right, beautiful. 79 00:05:12,760 --> 00:05:14,710 Now let's go ahead and save it. 80 00:05:16,810 --> 00:05:19,670 And now it's time to run that playbook. 81 00:05:19,690 --> 00:05:20,650 Ansible. 82 00:05:22,860 --> 00:05:28,230 Daesh playbook and name of that playbook. 83 00:05:29,630 --> 00:05:31,580 That e-mail hit Enter. 84 00:05:34,700 --> 00:05:35,270 All right. 85 00:05:35,270 --> 00:05:43,160 Running stat module as you have it here running stat module gathering facts against local host perfect 86 00:05:43,160 --> 00:05:44,930 check file status and attributes. 87 00:05:44,930 --> 00:05:51,440 This is the name of the task check, file, status and attributes All right against local host perfect 88 00:05:51,440 --> 00:05:59,180 now the message right here show what you got from the stat and then right here the message file attributes 89 00:05:59,180 --> 00:06:00,920 right here file attributes. 90 00:06:00,950 --> 00:06:01,520 Perfect. 91 00:06:01,520 --> 00:06:03,800 And these are the attributes it has. 92 00:06:04,160 --> 00:06:06,920 It has exist equal true. 93 00:06:06,920 --> 00:06:11,000 Which means the file is there perfect the passes as the host. 94 00:06:11,000 --> 00:06:15,950 The mod deserves the permission of that ATC host file. 95 00:06:16,340 --> 00:06:22,940 It has all the all the other information wherever you see false meaning that it does not have that. 96 00:06:22,940 --> 00:06:26,090 So if you notice, does it have a link? 97 00:06:26,090 --> 00:06:27,590 It says no, it's not a link. 98 00:06:27,590 --> 00:06:29,150 So that's why it's false. 99 00:06:29,180 --> 00:06:31,100 Uidai is zero. 100 00:06:31,100 --> 00:06:34,640 Group ID is zero because it's owned by root. 101 00:06:34,700 --> 00:06:37,640 I know number is you, I know a number. 102 00:06:37,640 --> 00:06:41,750 And then see time and time when it was created. 103 00:06:41,840 --> 00:06:50,390 These are all the information that you will get when you would actually run stat or or simply run ls 104 00:06:50,390 --> 00:06:54,620 on the command and you get some of the properties or attributes of a file. 105 00:06:55,400 --> 00:07:03,050 So the basic purpose of this video is to check if the file exists and of course to see what are the 106 00:07:03,050 --> 00:07:04,520 attributes of that file. 107 00:07:04,520 --> 00:07:13,130 You would need that in order to run certain commands, because many times you would run a script against 108 00:07:13,130 --> 00:07:13,580 a file. 109 00:07:13,580 --> 00:07:20,390 But of course, before you run that or execute any script, you need to first make sure it has the attributes 110 00:07:20,390 --> 00:07:21,770 or file exist. 111 00:07:21,980 --> 00:07:25,670 And you could run certain commands based on the result or attributes. 112 00:07:25,670 --> 00:07:26,510 You get it back.