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:30,000
no inventory was parsed, only implicit localhost is available. Now that is exactly what I need.

12
00:01:30,000 --> 00:01:40,879
So this works. That was easy. Now let me create a playbook using vimlab20.yaml. And in the

13
00:01:40,879 --> 00:01:49,839
playbook, I am going to define what I want to do. Name setup, setup web server, and hosts,

14
00:01:49,839 --> 00:01:58,199
localhosts, and tasks. And there I'm going to define my first task with the name, install

15
00:01:58,199 --> 00:02:05,800
the package. And then I'm using apt. In Ansible, it's always so that you should use the most

16
00:02:05,800 --> 00:02:13,160
Ansible way. So the most specific solution is always the best. And I'm using name, apache2.

17
00:02:13,160 --> 00:02:21,479
And then I'm going to use name, run the web server. And service is the name of the module.

18
00:02:21,479 --> 00:02:29,360
And name, apache2. And state is going to be started. And oh, I'm not so sure about it.

19
00:02:29,360 --> 00:02:35,919
You know what you can do in that case? You use Ansible doc on service in this case. I'm

20
00:02:35,919 --> 00:02:42,080
not sure about the service module arguments, and Ansible doc is giving me information about

21
00:02:42,119 --> 00:02:51,080
it. So here I can see that we have enabled. Enabled has a Boolean value. And we have state.

22
00:02:51,080 --> 00:02:56,520
And state has started, stopped, or reloaded, and so on. Well, now I know what I needed to know.

23
00:02:56,520 --> 00:03:07,160
So I can continue with state started and enabled true. Now I'm going to run it. And in case you

24
00:03:07,160 --> 00:03:12,520
are wondering, is this going to do anything? Well, if you listened carefully, probably not,

25
00:03:12,520 --> 00:03:19,240
because the current state should already meet the desired state as defined in this playbook.

26
00:03:19,240 --> 00:03:24,759
But that doesn't matter. We can still run it to guarantee consistency. So I need to think

27
00:03:24,759 --> 00:03:30,679
carefully. Ansible playbook, that's the command that I need. Minus b, I need become parameters.

28
00:03:30,679 --> 00:03:37,559
Minus b, I need become privileges. Minus k, we want to prompt for a password. Lab20.yaml,

29
00:03:37,559 --> 00:03:43,000
I think that should be it. We don't need an inventory. It can use my local username. And,

30
00:03:43,000 --> 00:03:48,759
oh boy, there we go. And we do have an issue anyway. Notice that the local host does not match

31
00:03:48,759 --> 00:03:57,479
all. So let me get back and hosts, local hosts. That's a typo. Local host, that is what we need.

32
00:03:58,279 --> 00:04:05,000
And now if I run it again, I enter my password. It's still complaining about the local host,

33
00:04:05,000 --> 00:04:09,880
which is giving me task install the package, OK, run the package, OK. And that is for the

34
00:04:09,880 --> 00:04:15,559
simple reason that the current state already meets the desired state on local host. So this is all.

