- So let's go develop a solution.
So this solution will be a little bit bigger
than the labs that we've seen so far.
So let's call a lab seven yaml.
In this solution we need to do a couple of things.
So we need to install vsftpd on all of the managed host
and copy the file etc vsftpd.
That's definitely the first phase.
So let's start with that
and let's do name copy conf file to local.
Posts all, tasks.
So what are we going to do?
Well in order to get a configuration file,
we are going to install vsftpd.
So that would be DNF.
No dash because it's just properties,
it's not the list.
Name vsftpd state latest.
And after installing it, we can use the fetch module.
So fetch the file.
In order to do that, we are using fetch
and this fetch-
Well in order to use fetch let's have a look
at the documentation.
It's always wise, especially for those models
that you don't use on a daily basis
to have a look at the documentation.
So there we go.
Ansible dot fetch, we need flat.
We need dest
and we need SRC.
I think that's enough, flat, dest and SRC.
So SRC.
That's what we start with, etc, vsftpd, vsftpd dot conf.
Flat, yes.
And destination TMP,
TMP vsftpd dot conf.
So that should be doing it.
And then we can do the second part.
And in the second part, we are going to work
on the file that we have just fetched to local.
So in order to do that second play, modify fell on control.
We are going to run that on local host,
become yes
just to ensure that we have sufficient permissions.
Then tasks and in tasks, what are going to do?
Well, we are going to add line to file.
If it's just one line that we need to add to a file
then line in file should be what we are doing.
So name tmp vsftpd dot conf.
And then line.
And what exactly is that line going to be?
Well, let's look it up once more,
ansible doc line in file.
I wanna have look at some examples.
So we have path, line and everything else,
I think path, line and that should be it.
We don't have to do anything very complex.
So let's just add the line.
I don't really mind where it is.
And if you do mind where it is
then you can always consider doing an insert after
or an insert before, but I am just going to use line
and we are going to specify what we want.
So what do we want?
Well, we want hash
written on ansible hostname,
so that should be doing it.
So that is, that is making sure that we have the template,
the template on the local machine
and now we can use a third play, finish it.
So, oops, I'm seeing syntax highlighting, not going well.
And I think we better look at the line
and the quoting in the line.
And what do we see?
We see that in the line, examples
there is quotes everywhere.
The quote is interesting because there's a hash here.
Hash has a special meaning.
So let's keep the quotes
and let's do a quote to the beginning.
And also to the end of this line.
Then we get the name, finish it, again on hosts, all.
At this point, we already have vsftpd installed.
I'm using default become parameters.
Obviously we do need tasks
and we are going to to first copy it.
So copy config.
Well, copy is the wrong word, use template.
So template is what we are going to do.
And oh, I made an error in line in file.
Do you see that?
That's what's happening when you are doing things
on the fly, it's always a bit confusing.
When do you need a dash to indicate a list?
And when don't you need it?
Well you don't need it to put arguments to a module.
So here SRC is going to be tmp vsftpd
and there I can see that something else
is going wrong as well.
So the SRC must be vsftpd dot j2.
We can easily fix that by tweaking the destination here
but we do want the template
to be in the j2 templating format.
So vsftpd j2
and then once more ansible doc template.
Some people like ansible doc minus S
to jump directly to the destination.
I don't do that.
I like seeing all of the documentation
so that if in any case, I need more information
about specific option, I don't have to run another command.
And what do we see?
We see source and destination, pretty straightforward.
So let's just keep it pretty straightforward.
Dest etc vsftpd
vsftpd dot conf.
And we don't need anything else.
Next, we are going to use name, start it.
Notice that I'm managing Red Hat here.
Rocky is Red Hat family, so I can use service
and in service, I can make sure that name vsftpd
as state, started and enabled, yes.
Oops, syntax highlighting is warning us
that we were forgetting something.
Already fixed that, last open firewall.
So that will be firewall D, name ftp.
This is firewall D and in firewall D
we are addressing services and it's just ftp
because it works also for pure ftp and other ftp processes.
And in firewall D the state and enabled an immediate,
that's worth checking as well,
because it's a little bit confusing.
So ansible doc on firewall D and in the example
we can see service and service is the name.
So we need service and permanent and state.
State is enabled and there is this immediate as well.
Isn't it?
And yeah, there we go.
So immediate, immediate, yes.
Permanent, yes.
State enabled and service is what we need.
So back here, service,
immediate, yes.
Permanent, yes.
And state enabled.
Just double checking
because these options are so close,
but there we go, state enabled.
That is what we need.
So that should be doing it.
Now, notice that I've been improvising here.
I like improvising.
That is because I know my stuff a little bit
and I give it a fair chance
that this is working out alright.
And my approach is, if it's not working out alright,
then we will see.
So ansible playbook on lab7 dot yaml
and we'll see what comes out of it.
So we go wrong in the second play,
add line to file.
Add line to file is telling me destination tmp vsftpd.
I can understand that because add line to file
it was just me overseeing it.
Shouldn't be adding anything to vsftpd dot conf.
It should be adding it to the j2 file.
We created the j2 file.
Before we are going on,
I might as well check and yeah, we can see the j2 exists.
Normally, if you want to create a playbook
that's a little bit more efficient,
especially in order to avoid doing things again and again.
You might want to use tags, but let's do that later.
I don't see any tags here.
What I do see is that, oh, in use template,
that is just too obvious.
I put it in tmp, not in etc.
But the thing is, if you use tags,
you can use a tag on every single play.
And if you use a tag on every single play
you can only run the place that need to be started again
and there we can see that vsftpd is available.
Is it, really?
Well let's do a quick check ansible
on ansible one minus a system ctl status vsftpd.
And I know that is not testing access through the firewall
but here we go, it's accessible.
So I think this is enough for lesson seven lab.
Let's move on with the next lesson.