1 00:00:00,930 --> 00:00:05,550 Imagine you have to create a user on hundreds of different Linux machines. 2 00:00:06,380 --> 00:00:09,800 Are you going to log into each and every machine and create a user? 3 00:00:09,980 --> 00:00:16,070 Well, if you do not have an automation system, then most likely, yes, you do have to do that and 4 00:00:16,070 --> 00:00:20,420 it's going to take you a lot of time and it's not very productive. 5 00:00:20,570 --> 00:00:23,750 That's when we have as well to automate that. 6 00:00:23,750 --> 00:00:31,310 So you could create users on your Linux or remote clients or even Windows remote clients from a few 7 00:00:31,310 --> 00:00:32,060 clicks. 8 00:00:32,060 --> 00:00:37,120 And we'll create it to as many systems as you have defined in the host file. 9 00:00:37,130 --> 00:00:42,590 So in this video, we are going to create a user on our remote client. 10 00:00:42,830 --> 00:00:47,600 So the playbook that we will write is going to create a user. 11 00:00:48,200 --> 00:00:57,470 George On a remote client, the user George will have a home directory as slash home slash George by 12 00:00:57,470 --> 00:01:00,440 the way, just ignore this uppercase George. 13 00:01:00,440 --> 00:01:02,210 It will have a lowercase g. 14 00:01:02,990 --> 00:01:07,070 The shell environment for user will be for the user. 15 00:01:07,070 --> 00:01:10,610 George will be slash bin and slash bash. 16 00:01:10,880 --> 00:01:18,170 You could define other parameters of a user when you create a user in the YAML file. 17 00:01:18,680 --> 00:01:19,190 All right. 18 00:01:19,190 --> 00:01:22,130 So we will create the YAML file and name it. 19 00:01:22,130 --> 00:01:28,370 Add user yaml, define the YAML parameters and define the name of the playbook. 20 00:01:28,460 --> 00:01:32,750 Then host which host you want to run it on and the tasks. 21 00:01:32,750 --> 00:01:36,830 This is all you are very familiar with right now. 22 00:01:36,860 --> 00:01:43,010 I'm sure you could write all of this up to this point with your eyes closed, now comes the task and 23 00:01:43,010 --> 00:01:47,150 what modules that you're going to be using first you need to create. 24 00:01:47,150 --> 00:01:53,240 The name of the task is to create users and the module that we will use is user module. 25 00:01:54,020 --> 00:02:00,050 If you want to know a lot different parameters that are using or options that are needed in the user 26 00:02:00,050 --> 00:02:05,390 module, of course you could go to the docs dot ansible dot com website. 27 00:02:05,870 --> 00:02:06,200 All right. 28 00:02:06,200 --> 00:02:07,580 So the module is defined. 29 00:02:07,580 --> 00:02:09,890 Now let's define the option with that module. 30 00:02:09,980 --> 00:02:11,510 The first thing is the name. 31 00:02:11,510 --> 00:02:15,080 What is the name that you want to give that user that you want to create? 32 00:02:15,110 --> 00:02:17,060 What is the home directory? 33 00:02:17,060 --> 00:02:21,290 We wanted to give it slash home and slash George. 34 00:02:21,290 --> 00:02:24,470 And the third thing that we want to define, it's Shell. 35 00:02:24,500 --> 00:02:27,650 We wanted to give it a shell slash spin and slash bash. 36 00:02:28,010 --> 00:02:34,040 Now if you wanted to pick a different user ID, you want to pick a different group or different information 37 00:02:34,040 --> 00:02:37,580 related to that user or even the description of the user. 38 00:02:37,580 --> 00:02:42,500 You could put all of that in this under the user module with the options. 39 00:02:42,890 --> 00:02:45,290 So right now we are just picking these three options. 40 00:02:45,290 --> 00:02:47,210 And then once that is defined, what do we do? 41 00:02:47,240 --> 00:02:52,430 We run our playbook by simply running add user dynamo with Ansible playbook. 42 00:02:52,820 --> 00:02:58,160 All right, let's go right into our Linux remote client. 43 00:02:58,160 --> 00:03:01,520 Let's make sure we do not have a user call. 44 00:03:02,180 --> 00:03:04,160 George So let's do ID. 45 00:03:04,250 --> 00:03:07,040 George and I will say no such user. 46 00:03:07,040 --> 00:03:14,480 All right, let's do Kat on Etsy password just to make sure there is no such user in the etsy password. 47 00:03:14,510 --> 00:03:24,170 There isn't any, but we could make it our search more specific by tapping it grep george etsy password 48 00:03:24,650 --> 00:03:25,910 and there isn't anything. 49 00:03:25,910 --> 00:03:26,960 Let's clear the screen. 50 00:03:27,980 --> 00:03:30,290 All right, so let's go to our control node. 51 00:03:30,290 --> 00:03:31,940 Let's write down. 52 00:03:34,540 --> 00:03:35,860 The playbook. 53 00:03:35,980 --> 00:03:36,340 All right. 54 00:03:36,340 --> 00:03:39,970 So we are in the Playbook directory. 55 00:03:40,000 --> 00:03:40,360 Good. 56 00:03:40,360 --> 00:03:46,300 Let's do vim, add user or any name that you want to pick for that playbook. 57 00:03:47,020 --> 00:03:49,150 Let's define it's a playbook. 58 00:03:49,330 --> 00:03:56,020 Let's put the name of the playbook playbook for creating users. 59 00:03:56,920 --> 00:03:57,460 All right. 60 00:03:57,460 --> 00:04:00,370 Host It could be specific. 61 00:04:00,370 --> 00:04:03,730 Host With the IP or host name or simply all. 62 00:04:03,820 --> 00:04:05,350 Then the tasks. 63 00:04:06,700 --> 00:04:16,720 And now the name of the task is to create users or user, then the module user. 64 00:04:16,960 --> 00:04:21,130 Now comes the option of the module, the name of the user that you want to create. 65 00:04:21,250 --> 00:04:27,190 George And the home directory of George will be home. 66 00:04:28,140 --> 00:04:32,400 George and the shell that user should have. 67 00:04:32,400 --> 00:04:34,650 The shell environment has been. 68 00:04:34,890 --> 00:04:36,810 BASH All right. 69 00:04:36,810 --> 00:04:37,950 It's just that simple. 70 00:04:37,980 --> 00:04:39,600 Go ahead and save the file. 71 00:04:39,630 --> 00:04:43,770 Now, let's go ahead and run our Ansible playbook. 72 00:04:43,770 --> 00:04:46,980 And the playbook name is add user yaml. 73 00:04:47,010 --> 00:04:47,790 Hit enter. 74 00:04:49,110 --> 00:04:54,720 All right, playbook for creating uses as the name we define task for all. 75 00:04:54,930 --> 00:05:00,690 And this is the IP address that was found inside of host file. 76 00:05:00,780 --> 00:05:01,230 All right. 77 00:05:01,230 --> 00:05:04,680 Anyway, it went to that host remote client and. 78 00:05:04,680 --> 00:05:05,850 Okay, nothing. 79 00:05:05,850 --> 00:05:07,740 No failure and change. 80 00:05:07,740 --> 00:05:09,220 Meaning one change that we asked. 81 00:05:09,300 --> 00:05:11,940 It means it created this user. 82 00:05:11,940 --> 00:05:15,330 So our playbook ran and was successful. 83 00:05:15,360 --> 00:05:16,140 Beautiful. 84 00:05:16,230 --> 00:05:18,810 Now let's confirm on the client side. 85 00:05:18,990 --> 00:05:25,350 So we'll do ID, George, and oops, let's put take out the slash at the end. 86 00:05:25,350 --> 00:05:26,250 And there you go. 87 00:05:26,280 --> 00:05:30,360 It's telling us the user ID has been created with George Group ID and groups. 88 00:05:30,510 --> 00:05:32,100 Now let's do Kat. 89 00:05:33,310 --> 00:05:34,660 On the password. 90 00:05:34,660 --> 00:05:35,890 Let's see right here. 91 00:05:35,890 --> 00:05:38,980 It's the George entry of the user. 92 00:05:38,980 --> 00:05:40,420 Is there? 93 00:05:40,840 --> 00:05:41,460 Nice. 94 00:05:41,470 --> 00:05:43,650 Now let's see if it has a home directory. 95 00:05:43,660 --> 00:05:46,280 Let's do KD slash home. 96 00:05:46,300 --> 00:05:48,340 Let's do LS minus later. 97 00:05:48,340 --> 00:05:50,740 And you notice it has two home directory. 98 00:05:50,740 --> 00:05:58,120 One is the regular user, which is my user and then the George Home Directory which we just created 99 00:05:58,120 --> 00:05:58,510 it. 100 00:05:58,960 --> 00:06:00,460 It's time seven everything. 101 00:06:00,640 --> 00:06:05,440 All right, so that's how you go and create a user's on your mobile client. 102 00:06:05,470 --> 00:06:11,380 Now, if you are installing an application, an application requires that you create a user for that 103 00:06:11,380 --> 00:06:12,190 application. 104 00:06:12,190 --> 00:06:16,080 And of course, for that you have to do it for hundreds of Linux machines. 105 00:06:16,090 --> 00:06:22,870 Then this playbook is going to come so handy and then you will be so thankful that you have access to 106 00:06:22,870 --> 00:06:23,680 this playbook.