1 00:00:00,850 --> 00:00:08,350 In this video we are going to copy files from our local host or ansible control node to our remote clients. 2 00:00:08,590 --> 00:00:14,600 If you copying one file from one location or one host to another host, it's fairly simple. 3 00:00:14,620 --> 00:00:22,600 You could just run a SIP command or any other command of Linux to copy from your local client to a remote 4 00:00:22,600 --> 00:00:23,190 client. 5 00:00:23,200 --> 00:00:28,300 But what if you have to copy that same file to multiple or hundreds of remote clients? 6 00:00:28,450 --> 00:00:30,610 Then that becomes a lot of work. 7 00:00:30,730 --> 00:00:36,610 So that's when you will use Ansible copy module to automate that task. 8 00:00:36,700 --> 00:00:37,030 All right. 9 00:00:37,030 --> 00:00:39,640 The first thing we'll do is we'll create some file. 10 00:00:39,670 --> 00:00:47,590 We'll call it some dot cfg file or config file, and we'll put that file inside of home files all directory. 11 00:00:47,590 --> 00:00:50,060 And that's just a random directory that I picked. 12 00:00:50,080 --> 00:00:51,910 You can pick any directory of your choice. 13 00:00:52,810 --> 00:00:59,590 Then we are adding some stuff, something that we are writing inside of that somewhat cfg file. 14 00:01:00,160 --> 00:01:06,390 All right, once that file is created, then we will use the vim editor and we'll name the file copy 15 00:01:06,760 --> 00:01:07,110 html. 16 00:01:08,470 --> 00:01:15,640 Once we are in editor will define it with dash, dash, dash and which you will tell the system that 17 00:01:15,640 --> 00:01:21,400 it's a YAML file and then the name copy file from local host to remote clients. 18 00:01:21,400 --> 00:01:23,590 Or you could pick any name of your choice. 19 00:01:23,590 --> 00:01:25,870 It's just a description of the play or playbook. 20 00:01:26,320 --> 00:01:34,840 Then the host run this playbook against the hosts or all the hosts that are in ETSI Ansible Host file, 21 00:01:35,740 --> 00:01:38,500 then the MTP line and then we have the task. 22 00:01:38,500 --> 00:01:45,160 And if you pay close attention once again, you'll notice the task is exactly vertically aligned right 23 00:01:45,160 --> 00:01:47,680 below the name and the host. 24 00:01:47,980 --> 00:01:53,410 So that's the task and it's telling us run the following task or list of tasks, but we are running. 25 00:01:53,410 --> 00:01:55,840 Only one task is to copy the files. 26 00:01:56,470 --> 00:01:59,660 Now what is the name of that task? 27 00:01:59,680 --> 00:02:01,210 Copying files. 28 00:02:01,570 --> 00:02:02,140 All right. 29 00:02:02,140 --> 00:02:03,910 And then become true. 30 00:02:03,910 --> 00:02:08,560 That said, additional added thing that I added in here. 31 00:02:09,250 --> 00:02:10,510 You don't have to add it. 32 00:02:10,510 --> 00:02:19,360 But in case you wanted to run this as a different user, or if you are running it as regular user and 33 00:02:19,360 --> 00:02:26,000 you wanted to run it as root, then you could use this option right now is telling you become true transfer 34 00:02:26,080 --> 00:02:26,890 as a crunch user. 35 00:02:26,890 --> 00:02:30,250 So if you logged in as root, it will transfer it as root. 36 00:02:30,320 --> 00:02:34,840 If you logged in as regular user or transfer as a regular user. 37 00:02:35,500 --> 00:02:36,220 All right. 38 00:02:36,220 --> 00:02:39,970 Now becomes the most important part of the playbook. 39 00:02:39,970 --> 00:02:41,350 The module. 40 00:02:41,380 --> 00:02:44,060 What module are we going to use to copy it? 41 00:02:44,080 --> 00:02:46,360 There is a copy module. 42 00:02:46,720 --> 00:02:47,320 All right. 43 00:02:47,710 --> 00:02:54,790 If you have that copy module, then of course it comes with other options and those options are source 44 00:02:54,790 --> 00:02:55,700 as RC. 45 00:02:55,720 --> 00:02:57,640 Just that that option is telling it. 46 00:02:57,670 --> 00:02:59,800 Where is the file located? 47 00:02:59,800 --> 00:03:02,440 And this is the source of the file. 48 00:03:02,530 --> 00:03:07,060 Now, if you are defining the source, then of course one more thing. 49 00:03:07,060 --> 00:03:10,120 You have to define the destination. 50 00:03:10,120 --> 00:03:10,920 Exactly. 51 00:03:10,930 --> 00:03:15,160 We are copying it from the Ansible control node from home. 52 00:03:15,160 --> 00:03:24,000 I absol some dot cfg to temp directory that's the destination of the file owner. 53 00:03:24,010 --> 00:03:27,300 Now it gives you additional information. 54 00:03:27,310 --> 00:03:29,200 You don't have to specify all that. 55 00:03:29,200 --> 00:03:31,630 If you want to transfer this route, it will transfer a route. 56 00:03:31,660 --> 00:03:38,920 Now, if you want the file that you are transferring to have a certain permissions and ownership, you 57 00:03:38,920 --> 00:03:42,100 could define it right here and you can put it in owner. 58 00:03:42,100 --> 00:03:45,910 I want to transfer as I have, so that's fine group. 59 00:03:46,450 --> 00:03:47,020 Okay. 60 00:03:47,020 --> 00:03:49,660 I want to transfer as a group as well. 61 00:03:50,480 --> 00:03:51,380 Excellent. 62 00:03:51,410 --> 00:03:53,060 Now, here's another thing. 63 00:03:53,060 --> 00:04:02,450 Yes, it gives you the mod or mod options, which will tell you if you wanted to change the permission 64 00:04:02,450 --> 00:04:03,410 of the file. 65 00:04:03,410 --> 00:04:10,190 So this will change the ownership and file permission of the file once it gets to the destination. 66 00:04:10,220 --> 00:04:13,670 See how granular it becomes. 67 00:04:13,670 --> 00:04:17,390 It goes down to details when it's going to copy the file. 68 00:04:17,660 --> 00:04:18,650 Excellent. 69 00:04:19,040 --> 00:04:24,140 Now we are going to create that playbook in our control mode. 70 00:04:24,140 --> 00:04:28,010 We'll run it and we'll check in our remote client. 71 00:04:28,550 --> 00:04:28,940 All right. 72 00:04:28,940 --> 00:04:35,060 So we'll first go to our Ansible control node, which is right here. 73 00:04:37,760 --> 00:04:39,200 Log in as route. 74 00:04:44,000 --> 00:04:46,220 All right, we're logged in as route. 75 00:04:46,490 --> 00:04:49,700 And let's move this down right here. 76 00:04:49,730 --> 00:04:55,040 Let's go to our at sea and Symbol Playbooks directory. 77 00:04:55,400 --> 00:05:00,520 Here we are going to create the vim file. 78 00:05:00,530 --> 00:05:06,800 But before we do the vim file, let's put do echo some stuff. 79 00:05:08,310 --> 00:05:11,180 And I'll put that to home. 80 00:05:11,190 --> 00:05:12,360 I have all. 81 00:05:13,120 --> 00:05:14,950 Some dos cfg. 82 00:05:15,280 --> 00:05:20,980 All right, so you'll notice this file has been created in my home directory right here. 83 00:05:20,980 --> 00:05:22,090 Some cfg. 84 00:05:22,330 --> 00:05:23,860 And when I do cat. 85 00:05:29,040 --> 00:05:29,640 Someday. 86 00:05:29,880 --> 00:05:32,570 If you want to do cat it, is there some stuff? 87 00:05:32,720 --> 00:05:36,930 Okay, let's go back to our Etsy playbook. 88 00:05:36,930 --> 00:05:38,250 Our file is there. 89 00:05:38,430 --> 00:05:39,960 That's clear the screen. 90 00:05:39,990 --> 00:05:40,710 Sorry. 91 00:05:41,840 --> 00:05:45,680 Now let's do him and copy the YAML. 92 00:05:47,000 --> 00:05:48,110 Define that. 93 00:05:48,110 --> 00:05:49,430 It's a YAML file. 94 00:05:49,790 --> 00:05:51,320 Define the name. 95 00:05:53,170 --> 00:05:57,940 Copy file from local host to remote clients. 96 00:05:59,550 --> 00:06:00,540 Host. 97 00:06:03,340 --> 00:06:06,280 All tasks. 98 00:06:08,000 --> 00:06:09,530 Dash name. 99 00:06:10,910 --> 00:06:12,800 Copying file. 100 00:06:12,800 --> 00:06:16,340 This is what the task will do become. 101 00:06:16,340 --> 00:06:16,730 Oops. 102 00:06:16,730 --> 00:06:17,410 Sorry. 103 00:06:17,420 --> 00:06:19,040 You notice one thing. 104 00:06:20,610 --> 00:06:23,940 There has to be space right here, so be very careful. 105 00:06:24,600 --> 00:06:31,380 Now when you hit enter, it will automatically do the indentation for you to put that vertically below 106 00:06:31,590 --> 00:06:32,450 the end. 107 00:06:32,460 --> 00:06:33,540 Or the name. 108 00:06:34,260 --> 00:06:35,400 Now become. 109 00:06:38,220 --> 00:06:39,030 True. 110 00:06:39,300 --> 00:06:43,810 As the same user used the module copy. 111 00:06:43,830 --> 00:06:44,760 Excellent. 112 00:06:44,910 --> 00:06:51,940 Now once you define the module and hit enter, the system knows that this module has been added. 113 00:06:51,960 --> 00:06:59,070 Now when the user hit enter, I will automatically do the indentation for him or her. 114 00:06:59,190 --> 00:06:59,730 All right. 115 00:07:00,510 --> 00:07:03,600 And the options source. 116 00:07:04,870 --> 00:07:12,100 Slash home, slash eye of salt dash some dot cfg destination. 117 00:07:13,070 --> 00:07:14,210 Just temp. 118 00:07:15,160 --> 00:07:16,820 All right, owner. 119 00:07:16,900 --> 00:07:18,870 Who do you want it to transfer it as? 120 00:07:18,880 --> 00:07:21,420 I want to have it. 121 00:07:21,430 --> 00:07:28,690 The ownership change to I absolve the group ownership change to I absol if I don't do it then it will 122 00:07:28,690 --> 00:07:31,480 be transferred as route and the mode. 123 00:07:31,480 --> 00:07:39,520 I want to change it to 0644, which is telling it that I want to have read permission for everyone and 124 00:07:39,520 --> 00:07:42,610 only write permission for the owner of the file. 125 00:07:43,580 --> 00:07:44,180 All right. 126 00:07:44,420 --> 00:07:47,960 This is this completes our playbook. 127 00:07:48,890 --> 00:07:49,370 All right. 128 00:07:49,370 --> 00:07:50,120 Excellent. 129 00:07:50,240 --> 00:07:52,240 Now, I will. 130 00:07:52,250 --> 00:08:02,000 Before I run the playbook, I wanted to make sure that at Sea Ansible host which we have right here, 131 00:08:02,360 --> 00:08:04,580 this is the host. 132 00:08:04,760 --> 00:08:07,650 That's the only IPV have for our client. 133 00:08:07,670 --> 00:08:15,950 I want to make sure I could ping that because I rebooted the system and my system remote client is running 134 00:08:15,980 --> 00:08:21,890 on DHCP, so it might or its IP might have changed. 135 00:08:21,950 --> 00:08:24,050 So I wanted to ping it first. 136 00:08:24,710 --> 00:08:28,400 10.2 53.1 .115. 137 00:08:28,760 --> 00:08:29,450 All right. 138 00:08:29,750 --> 00:08:30,200 Perfect. 139 00:08:30,200 --> 00:08:31,930 It means its IP is the same. 140 00:08:31,940 --> 00:08:33,350 It did not change. 141 00:08:33,980 --> 00:08:34,580 Perfect. 142 00:08:34,580 --> 00:08:35,750 Let's clear the screen. 143 00:08:35,750 --> 00:08:38,540 And now let's run our Ansible. 144 00:08:39,420 --> 00:08:46,650 Playbook and we are already in playbook, so we don't need to define the entire absolute path for our 145 00:08:46,650 --> 00:08:47,270 playbook. 146 00:08:47,280 --> 00:08:55,500 So we'll just put in copy YAML and hit enter and it is telling us copy file from local host to remote 147 00:08:55,500 --> 00:09:02,130 clients, which is the name right here, gathering task to which host change to this is the host IP 148 00:09:02,130 --> 00:09:06,990 address that it found inside of the host file. 149 00:09:07,780 --> 00:09:08,710 Player recap. 150 00:09:08,710 --> 00:09:09,430 This is it. 151 00:09:09,580 --> 00:09:10,090 Okay. 152 00:09:10,090 --> 00:09:11,320 To done change. 153 00:09:11,320 --> 00:09:11,650 Done. 154 00:09:11,650 --> 00:09:16,610 It means it has completed its task successfully. 155 00:09:16,630 --> 00:09:20,110 Now to confirm we will go to our. 156 00:09:23,930 --> 00:09:25,060 Remote client. 157 00:09:25,070 --> 00:09:26,900 Here is our email client. 158 00:09:29,460 --> 00:09:31,320 And I'm going to log in as root. 159 00:09:31,680 --> 00:09:38,430 And we asked the playbook to copy the file in the destination slash temp. 160 00:09:38,760 --> 00:09:45,720 So we'll do CD slash temp and the moment of truth is let's do ls minus l tr. 161 00:09:45,720 --> 00:09:49,410 And the file is right here, guys. 162 00:09:50,740 --> 00:09:54,460 Some dos cfg or let's clear the screen. 163 00:09:54,460 --> 00:10:01,210 You could just do ls minus l some dos cfg and it will tell you that it has been transferred. 164 00:10:01,570 --> 00:10:07,030 Check the content cat, some de cfg and some stuff is in there. 165 00:10:07,180 --> 00:10:07,990 Excellent. 166 00:10:07,990 --> 00:10:09,250 Congratulations. 167 00:10:09,250 --> 00:10:16,900 You have just completed your playbook in which you can copy files to so many of your remote clients. 168 00:10:16,900 --> 00:10:21,880 Now you can copy to as many remote clients as you want if you have them. 169 00:10:21,880 --> 00:10:23,260 And it's the same way. 170 00:10:23,260 --> 00:10:29,290 If you wanted to move all file, you can use the MOV module and many of the things that you could do 171 00:10:29,290 --> 00:10:36,130 with this module, you could check the list of options available to you from the documentation.