1 00:00:00,540 --> 00:00:08,130 In this video, we will write a playbook that will allow us to change file permission of a file at a 2 00:00:08,130 --> 00:00:09,180 remote client. 3 00:00:09,450 --> 00:00:15,390 So the first thing we have to do is we'll log into our Linux client, which is our remote client, and 4 00:00:15,390 --> 00:00:22,650 we'll create a dummy file and we'll call it Linux two in home Excel Directory. 5 00:00:22,650 --> 00:00:27,750 You could create it anywhere you want, but then you have to specify the right location. 6 00:00:27,780 --> 00:00:33,180 All right, so once file is created, let's come back to our control node and we'll start writing our 7 00:00:33,180 --> 00:00:37,500 YAML file and name it file permissions yaml. 8 00:00:38,250 --> 00:00:38,640 All right. 9 00:00:38,640 --> 00:00:43,620 Once we are in the YAML file editor, what's the first thing we do? 10 00:00:44,350 --> 00:00:49,750 We define a dash, dash, dash, so we know that it's YAML file. 11 00:00:49,780 --> 00:00:51,960 Then we have to put down the name. 12 00:00:51,970 --> 00:00:58,060 That's the name of our playbook change file permissions or if you are doing additional task, then you 13 00:00:58,060 --> 00:01:00,970 put down a summary of that tasks. 14 00:01:01,690 --> 00:01:02,020 All right. 15 00:01:02,020 --> 00:01:10,270 So host, you already know anything that we have in our slash at see ansible host file all of those 16 00:01:10,270 --> 00:01:11,950 hosts will be. 17 00:01:12,720 --> 00:01:14,250 Part of this change. 18 00:01:14,250 --> 00:01:16,020 So be putting down all. 19 00:01:17,190 --> 00:01:21,320 Then we have an empty line and then we defining the task. 20 00:01:21,330 --> 00:01:28,350 The task again is indented, indented and it's vertically aligned where name and hostess. 21 00:01:28,350 --> 00:01:29,700 And so what's the task? 22 00:01:29,700 --> 00:01:34,740 The task name is changing file permissions or file permissions only. 23 00:01:35,040 --> 00:01:40,050 All right, then we will use the module, and the module is file. 24 00:01:40,050 --> 00:01:48,450 In this case, yes, we are dealing with file systems, so we will use the file module. 25 00:01:48,480 --> 00:01:48,840 All right. 26 00:01:48,840 --> 00:01:57,210 So now the path the path where the file location is, this is the location of the file that we have 27 00:01:57,210 --> 00:01:58,320 to modify. 28 00:01:58,500 --> 00:01:59,010 All right. 29 00:01:59,010 --> 00:02:01,740 So we have to use mod then. 30 00:02:01,740 --> 00:02:10,740 And the mod we could use letters for defining a plus w meaning we want the file to have right permission 31 00:02:10,740 --> 00:02:14,130 for everyone and that A stands for all. 32 00:02:14,340 --> 00:02:20,610 You can also use numerical digits to define the mode as well. 33 00:02:20,610 --> 00:02:27,120 So either digits or letters, whichever you are comfortable with, and that's where you define the permission. 34 00:02:27,720 --> 00:02:30,360 Once that is done, then you run the playbook. 35 00:02:30,360 --> 00:02:38,280 And don't forget all your modules and its options are available in docs dot dot com, slash ansible, 36 00:02:38,310 --> 00:02:40,200 the version and the modules. 37 00:02:40,200 --> 00:02:44,700 You get the list of all the modules that are available out of the box for you. 38 00:02:44,910 --> 00:02:45,510 All right. 39 00:02:45,510 --> 00:02:49,890 Let's get right into our Linux boxes and let's start writing the playbook. 40 00:02:49,890 --> 00:02:54,240 The very first box that we'll get in is our client. 41 00:02:55,680 --> 00:02:57,600 And I am logged in as root. 42 00:02:57,630 --> 00:02:59,460 Already you can log in as you saw. 43 00:02:59,460 --> 00:03:00,660 It doesn't really matter. 44 00:03:00,690 --> 00:03:02,460 I am in temp directory. 45 00:03:03,000 --> 00:03:03,810 Who am I? 46 00:03:03,840 --> 00:03:04,980 Am logged in as Ruth. 47 00:03:05,010 --> 00:03:10,680 Let's go to home iocl and let's touch Linux to. 48 00:03:11,310 --> 00:03:15,840 All right, let's see the permissions that are given to Linux two you see right here. 49 00:03:15,930 --> 00:03:19,320 RW Dash, ah dash are dash, dash. 50 00:03:19,320 --> 00:03:24,120 So it means everyone can read it, but only root can write to it. 51 00:03:24,120 --> 00:03:28,020 So when we run this playbook, it should give right permissions. 52 00:03:28,020 --> 00:03:28,580 Right. 53 00:03:28,590 --> 00:03:29,160 All right. 54 00:03:29,160 --> 00:03:31,080 So that's what it is. 55 00:03:31,080 --> 00:03:31,590 We create it. 56 00:03:31,590 --> 00:03:37,320 Now let's go to our control node and here is our control node. 57 00:03:38,530 --> 00:03:43,690 Let's log in as route and I'm already in playbooks. 58 00:03:43,690 --> 00:03:44,590 Who am I? 59 00:03:44,590 --> 00:03:46,000 Am logged in as a root. 60 00:03:46,150 --> 00:03:46,900 Excellent. 61 00:03:46,900 --> 00:03:51,220 So when I'm file permission dot yaml. 62 00:03:51,730 --> 00:03:52,450 Dash, dash. 63 00:03:52,450 --> 00:03:54,790 Dash, dash and dash. 64 00:03:55,750 --> 00:03:59,350 Name off the playbook or the play. 65 00:04:00,870 --> 00:04:01,890 Change. 66 00:04:02,880 --> 00:04:04,560 File permissions. 67 00:04:04,830 --> 00:04:05,730 All right. 68 00:04:05,950 --> 00:04:12,030 Host you could put local hosts if you are putting if you're making a change on this local host or simply 69 00:04:13,320 --> 00:04:18,480 put a space tasks and then name. 70 00:04:20,310 --> 00:04:23,880 Of that specific task permission. 71 00:04:25,630 --> 00:04:26,340 All right. 72 00:04:26,340 --> 00:04:28,830 The file is the module. 73 00:04:28,830 --> 00:04:35,490 And once the module is defined, it will automatically advance or give you the right indentation to 74 00:04:35,490 --> 00:04:37,210 put the parameters. 75 00:04:37,230 --> 00:04:40,470 The path path is home is all. 76 00:04:40,470 --> 00:04:42,320 And here is the file. 77 00:04:42,330 --> 00:04:43,140 Linux two. 78 00:04:43,140 --> 00:04:49,800 And what do you want to change its permission to all should have a write permission. 79 00:04:49,920 --> 00:04:51,270 All right, that's good. 80 00:04:51,270 --> 00:04:53,070 Let's save the file. 81 00:04:53,160 --> 00:05:00,540 Playbook is done now let's run it Ansible dash playbook file permission yaml. 82 00:05:01,320 --> 00:05:09,510 All right so it will go through the play change file permission right here to all here is our client 83 00:05:09,510 --> 00:05:18,270 and the client tasks changed and okay to and right here says changed meaning what you have asked has 84 00:05:18,270 --> 00:05:19,410 been completed. 85 00:05:20,150 --> 00:05:20,900 Beautiful. 86 00:05:21,050 --> 00:05:26,960 Now to confirm that on our client will go to our client machine right here. 87 00:05:26,960 --> 00:05:29,420 This was the permission. 88 00:05:29,420 --> 00:05:33,050 And when we do ls minus l t again. 89 00:05:33,080 --> 00:05:41,510 Now, this is the new permissions that are given to this file through our playbook. 90 00:05:41,660 --> 00:05:47,240 All right, so now you'll learn how you could change permissions using the file module. 91 00:05:47,250 --> 00:05:52,850 You could do a lot of other things, the permissions, the ownership of a file to this module.