1 00:00:00,000 --> 00:00:12,520 For this lab, I'm going to set up Ubuntu Desktop as an Ansible control host. Can you do that? 2 00:00:12,520 --> 00:00:19,920 Yes, you can. I'll show you. I'll start by using sudo apt install ansible-core. The ansible-core 3 00:00:19,920 --> 00:00:27,799 package is available in the distribution repositories for many distributions. So it wants to install 4 00:00:27,799 --> 00:00:33,439 a couple of packages and that is okay. So here we go. Now I want to set up this machine 5 00:00:33,439 --> 00:00:40,160 so that it can manage itself. Now that sounds funny, but you can. But even if I'm going 6 00:00:40,160 --> 00:00:46,919 to use localhost, I do need SSH access. So I'm going to start with an SSH keygen. And 7 00:00:46,919 --> 00:00:57,599 there I'm going to use SSH copy ID to localhost. Because I need to be able to use SSH localhost 8 00:00:58,000 --> 00:01:04,360 without entering a password. That's good. My current user already has superuser privileges, 9 00:01:04,360 --> 00:01:12,279 so that should be okay. And I don't need an inventory because localhost is always available. 10 00:01:12,279 --> 00:01:24,320 So it's time for our first test. Ansible localhost minus m ping. And there we can see the warning, 11 00:01:24,320 --> 00:01:29,480 no inventory was parsed, only implicit localhost is available. Well, that is exactly what I 12 00:01:29,480 --> 00:01:40,639 need. So this works. That was easy. Now let me create a playbook using vimlab20.yaml. 13 00:01:40,639 --> 00:01:48,279 And in the playbook, I am going to define what I want to do. Name setup, setup web server, 14 00:01:48,279 --> 00:01:56,480 and hosts, local hosts, and tasks. And there I'm going to define my first task with the 15 00:01:56,480 --> 00:02:05,120 name, install the package. And then I'm using apt. In Ansible, it's always so that you should 16 00:02:05,120 --> 00:02:11,039 use the most Ansible ways. So the most specific solution is always the best. And I'm using 17 00:02:11,039 --> 00:02:20,160 name, apache2. And then I'm going to use name, run the web server. And service is the name of 18 00:02:20,160 --> 00:02:29,240 the module. And name, apache2. And state is going to be started. And oh, I'm not so sure about it. 19 00:02:29,240 --> 00:02:36,240 You know what you can do in that case? You use Ansible doc on service in this case. I'm not sure 20 00:02:36,360 --> 00:02:44,160 about the service module arguments. And Ansible doc is giving me information about it. So here I can 21 00:02:44,160 --> 00:02:52,240 see that we have enabled. Enabled has a Boolean value. And we have state. And state has started, 22 00:02:52,240 --> 00:02:59,080 stopped, or reloaded, and so on. Well, now I know what I needed to know. So I can continue with 23 00:02:59,080 --> 00:03:08,199 state started and enabled. True. Now I'm going to run it. And in case you are wondering, is this 24 00:03:08,199 --> 00:03:13,600 going to do anything? Well, if you listened carefully, probably not, because the current 25 00:03:13,600 --> 00:03:20,160 state should already meet the desired state as defined in this playbook. But that doesn't matter. 26 00:03:20,160 --> 00:03:26,559 We can still run it to guarantee consistency. So I need to think carefully. Ansible playbook, 27 00:03:26,600 --> 00:03:31,960 that's the command that I need. Minus b, I need become parameters. Minus b, I need become 28 00:03:31,960 --> 00:03:38,800 privileges. Minus k, we want to prompt for a password. Lab20.yaml. I think that should be it. 29 00:03:39,080 --> 00:03:45,720 We don't need an inventory. It can use my local username. And oh boy, there we go. And we do have 30 00:03:45,720 --> 00:03:52,800 an issue anyway. Notice that the local host does not match all. So let me get back and hosts, local 31 00:03:52,800 --> 00:04:00,839 hosts. That's a typo. Local host. That is what we need. And now if I run it again, I enter my 32 00:04:00,839 --> 00:04:07,320 password. It's still complaining about the local host, which is giving me task install the package 33 00:04:07,320 --> 00:04:12,839 okay, run the package okay. And that is for the simple reason that the current state already meets 34 00:04:12,839 --> 00:04:15,679 the desired state on local host. So this is all.