For this lab, I'm going to set up Ubuntu Desktop as an Ansible control host. Can you do that?
Yes, you can. I'll show you. I'll start by using sudo apt install ansible-core. The ansible-core
package is available in the distribution repositories for many distributions. So it wants to install
a couple of packages and that is okay. So here we go. Now I want to set up this machine
so that it can manage itself. Now that sounds funny, but you can. But even if I'm going
to use localhost, I do need SSH access. So I'm going to start with an SSH keygen. And
there I'm going to use SSH copy ID to localhost. Because I need to be able to use SSH localhost
without entering a password. That's good. My current user already has superuser privileges,
so that should be okay. And I don't need an inventory because localhost is always available.
So it's time for our first test. Ansible localhost minus M ping. And there we can see the warning,
no inventory was parsed, only implicit localhost is available. Now that is exactly what I need.
So this works. That was easy. Now let me create a playbook using vimlab20.yaml. And in the
playbook, I am going to define what I want to do. Name setup, setup web server, and hosts,
localhosts, and tasks. And there I'm going to define my first task with the name, install
the package. And then I'm using apt. In Ansible, it's always so that you should use the most
Ansible way. So the most specific solution is always the best. And I'm using name, apache2.
And then I'm going to use name, run the web server. And service is the name of the module.
And name, apache2. And state is going to be started. And oh, I'm not so sure about it.
You know what you can do in that case? You use Ansible doc on service in this case. I'm
not sure about the service module arguments, and Ansible doc is giving me information about
it. So here I can see that we have enabled. Enabled has a Boolean value. And we have state.
And state has started, stopped, or reloaded, and so on. Well, now I know what I needed to know.
So I can continue with state started and enabled true. Now I'm going to run it. And in case you
are wondering, is this going to do anything? Well, if you listened carefully, probably not,
because the current state should already meet the desired state as defined in this playbook.
But that doesn't matter. We can still run it to guarantee consistency. So I need to think
carefully. Ansible playbook, that's the command that I need. Minus b, I need become parameters.
Minus b, I need become privileges. Minus k, we want to prompt for a password. Lab20.yaml,
I think that should be it. We don't need an inventory. It can use my local username. And,
oh boy, there we go. And we do have an issue anyway. Notice that the local host does not match
all. So let me get back and hosts, local hosts. That's a typo. Local host, that is what we need.
And now if I run it again, I enter my password. It's still complaining about the local host,
which is giving me task install the package, OK, run the package, OK. And that is for the
simple reason that the current state already meets the desired state on local host. So this is all.