- All right, let's create a solution for this lab.
So I am creating,
lesson3.yaml.
And we need to start with the three hyphens
and then the play header.
So what are we going to do?
Install and run vsftpd.
We run it on hosts all,
and then we specify the tasks.
Task number one.
Name, install the package.
So definitely we need the packages
and packages need to be vsftpd.
Then, oops that's not good.
I'm using package.
Package is not name of the package.
It's the name of the module.
So vsftpd is an argument
to that module, so this is how I need to do it.
Package name vsftpd.
Then we are going to use name,
run the service.
And in order to do so,
we use a service module,
and in the service module,
we use name vsftpd,
state started.
Enabled, yes.
Now, this is something that you need to double check,
because myself, I'm always confused about the state
and enable and stuff like that.
Easiest way to double check,
go to Ansible doc
and have a look at what you can see here.
So we can see states.
Here we have state started.
Here we have enabled, yes.
So that is okay.
State started, enabled yes is what it is.
Then we have the firewall.
Open firewall, and I'm going
to use firewall d
and I'm using name.
Name, you said name?
Again, I need to check this
in my documentation, Ansible doc.
So in firewall d, we are not using name.
We're using service.
So we have permanent state and immediate.
So service, permanent state, immediate.
So let's give it service vsftpd,
state
and now forgot which options to use, state enabled.
Permanent, yes.
And immediate, yes.
And hey, do you see what's going wrong?
Wrong lib syntax highlighting.
D's and L's have syntax highlighting.
I forgot a colon.
You know what?
Let's just run it while forgetting the colon
and see, are we really don't need
to do any syntax checking
to figure out if it's doing all right?
So Ansible playbook on,
lesson3.yaml, is telling me what?
It's telling me, oh, we have a problem
and the problem seems to be here.
As you can see, it's pretty accurate.
So based on that information,
we can easily identify that firewall d needs a colon.
One more thing.
I just changed my mind.
Of course we can write a playbook
that will do this on Ubuntu and on Rocky as well.
But at this stage in the course,
it's not reasonable to expect
that you can already do that.
So I'm skipping the Ubuntu part
and we make this Rocky exclusively.
So here we go.
Again, we are running the playbook.
Oh, one more thing.
Do we need facts?
I don't need facts.
Gather facts set to no, there we go.
It'll speed it up a little bit.
Packages are not a part of the fact anyway.
So it'll use yam to figure out
if the packaging is installed, yes or no.
And yam is using this cache
and this cache is always slow.
And that's just the way, how it is.
You might want to consider optimizing yam and yam cache
if you want to speed up that procedure,
which for now we need to wait
and sit it out and see what the result is going to be.
So there we go.
The package is installed right now.
It is running the service,
and once the service is started,
it should go to firewall and we should be good.
And oh no.
What do we get?
We get an invalid service on the firewall.
So what is happening?
Yeah, vsftpd is not amongst the existing services.
Let me do a quick check.
Firewall c and d.
Dash dash, get services,
is showing all the services that we have available
and it's not vsftpd,
it's FTP, as you can see right here.
So we need to run it again,
and we need to make that not the d and just FTP.
So this should be doing it.
Let's go there again.
So now we can see that the firewall is open
and hey, if you want to do it again,
run it one more time to verify the item potency.
And there we go.
As you can see, this is a nice
idempotent playbook, mission accomplished.