So friends, now that we know the basics behind mounting, let's now use Ansible
to perform
this particular task. So as you will know, all of these actions that we do to
create
the particular mount points can be created just by specifying a particular
command on
the command line. And as such, what we can do is invoke the Ansible built in
command module.
However, whilst this is a totally valid configuration, the problem is is that
just by using this
particular module on its own is not going to be idempotent. As such, what we
want to do is be
wanting to explore the potential modules that we have at play that are WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
wanting to explore the potential modules that we have at play that are
dedicated for this
particular task that will be idempotent. So what we're going to do is utilize
the Ansible
POSIX collection. This is one we've seen before earlier on within this course,
but the particular
module we want to be looking at is the mount module within this particular
collection.
So how we're going to use it, the best place we should go is to the actual
documentation itself.
So let's pull up our browser and get to it. So if you search for the Ansible
Mount module,
and collect this top link right here, it's going to take us to this particular WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
and collect this top link right here, it's going to take us to this particular
page.
Or once again, this is not a part of Ansible course. So if you do not have this
collection,
then by all means copy this particular command and paste it into the terminal
of your control
node. So once you have access to this particular module, we can use it by
specifying the fully
qualified collection name, which is going to be Ansible.posix.mount. And if we
just scroll down
a little bit, we're going to see this in notice about what this particular
module is going to do.
It says here it's going to allow us to control active and configure mount WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
It says here it's going to allow us to control active and configure mount
points in say FS tab.
Now this is something we didn't discuss in the previous videos a lot, which
briefly mentioned it.
When we just happen to specify a particular mount points, just manually using
the mount command,
when we happen to restart the machine, i.e. the actual server, what is going to
happen is that the
particular device that happened to be mounted is going to be automatically un
mounted upon the
reboot. If we want the actual mount to persist through reboot so that it is WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
reboot. If we want the actual mount to persist through reboot so that it is
always accessible
within the reboot, we have to make a modification in the acfs tab file. So let
me just briefly
show you that for one moment. So even if I just go into my control mode right
here, if I go into
acfs tab, go into insert mode, what we actually see here is we see the uuid of
the actual device
itself. This is the number right here. We can also specify a label name if we
so wish,
and then we specify the mount points. So in this case here, that says the root
directory, the one
below we see the boot EFI, and then the next column is going to be the actual WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
below we see the boot EFI, and then the next column is going to be the actual
file system itself.
So we can see here the file system is going to be xfs, and then we can specify
some default
values which we don't have to concern ourselves with right now. So basically
and say this particular
file here, all we're doing is specifying these particular devices that we want
to mount,
where we actually want to mount them. So for example, in this directory or this
directory,
as well as the file system type, and that means that these particular devices
will always be
accessible, they will always be mounted even if the system is rebooted. So WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
accessible, they will always be mounted even if the system is rebooted. So
revisiting back,
we do have some particular parameters that we want to discuss here. So this
particular option here
is quite important. We have the boot option, and this is going to be specified
using a boolean value,
either true, which is the default or false. Now basically, when we set the
value to true,
what we're going to see is we do want the file system to be mounted on boots.
Okay. Now, if we
happen to specify the value false, we will make the modification within it say, WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
happen to specify the value false, we will make the modification within it say,
fstab. But we're
going to effectively add the no auto mount to the options within the particular
file, so it will not
be mounted automatically. If we specify that particular value, but like I said,
by default,
we will have that persistent mounting. And that is in this case here, what we
're going to do.
Now, if we just scroll on down a little bit further here, now this one here is
pretty important.
We have the fstite, we're going to specify a string value. And this is the file
system type
that we are effectively mounting. So is it going to be an ext4 file system we WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
that we are effectively mounting. So is it going to be an ext4 file system we
're trying to mount,
or perhaps maybe it's an XFS, maybe it's a VFA, whatever it may be, this is the
parameter that we
will use to specify that particular configuration. Now, scrolling on down, this
one here is a very,
very important one. This is the path parameter. And we can see here this is a
required parameter.
We must specify this. Okay. Now pretty much we use this particular parameter to
specify the
actual mount point. This is like the directory where we want to have the device
be mounted. WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
be mounted.
Now, what is it we would actually like to mount? We can use that with the SRC
parameter,
basically the source parameter. This is how we specify the actual device that
we want to be
mounted on the path we had just specified. Now, if we so wish we can specify a
label,
or if we so choose like we saw in the SSA FST half file, we can specify the
device's universal
unique identifier. Now scrolling on down, we also have yet another very, very
important parameter.
This is the state parameter. And we can see here this is actually required. So WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
This is the state parameter. And we can see here this is actually required. So
the values we can
specify are things like mounted. And if we provide that particular value, the
device is going to be
actively mounted and configured in a FSTab. Notice if we specify unmounted, the
device is going to be
unmounted without actually changing a FSTab. So pretty much if we specify un
mounted, we're going
to unmounted the device. But if we happen to rebut, it's still going to be
present in a FSTab.
And therefore it could be remounted upon a rebut. Whereas if we specify the
value absent here, WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
value absent here,
this is actually going to remove the entry from a FSTab, as well as unmounted
device and remove
the mount points of very, very different. So as you can see, we have a whole
bunch of options
available to us. How about we go and write a playbook to try using this
particular module.
So let's go back to the control mode right now. So let's create a playbook
called play3.YML.
That's going to insert mode half or three hyphens at the top. Let's give this
playbook a name,
we'll just call it play3 testing the mount module. Now what are we going to
target? In this case WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
target? In this case
here, let's maybe target, oh, let's go with the blue box. Okay. And we'll set
gather facts to be
the billion value of false. And let me define my task. And the very first task
I'm going to do
is I'm going to actually create a mount point. So just say create a mount point
. So I want to
create a new directory. So I'm going to use the animal built in file module,
which we saw in an
earlier scale. And I'm going to provide the path parameter. This is going to be
where the actual
device is going to reside. So let's maybe create it in the home nugget user
directory. WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
directory.
And let's create a directory. Let's maybe call it, let's just say nugget mount.
Okay. I'll specify
the state as a directory. And they'll give it some permissions. So I'll say the
permissions are,
let's maybe go with 077. Let's be super relaxed just because it is a demo right
now. So that can
be the first task. The next task is going to be to actually mount the actual
device itself.
So what I will do here is I will have a new name for a second task and I'll
just say mount a device. WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
So in this case here, what I'm going to use is the Ansible POSIX mount module.
And I'm going to
specify the path parameter. Now, where do I want to mount the actual device?
Well, I'm going to mount
it in this newly created directory that I'm going to actually generate. Now I
can specify
the source right here. This is going to allow me to determine what device I
want to actually
mount. Then my case here, and it's going to hard code a value, which is going
to be NVMe 0.0.
But just like with all of these options, if I so wished I could pass in a
variable value, WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
variable value,
which would be much more realistic if I happen to be automating across many
different devices.
But for now, let's just focus in on using some hard coded values. And now what
I want to do is
I want to specify the file system type. Now think about it like this. Let's go
back to our device
right here. I'm on the blue box, if I do an LSBLK dash F, this here is a device
that I want to be
mounting and it actually has an XFS file system notice right now it doesn't
actually have a mount
points. Now what we could also do by the way is we could take this universal
unique identifier WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
unique identifier
and we could identify the source using this particular value if we so wished.
But for now,
we're not going to worry about that. We'll just specify the value as XFS for
the first system type.
And now we're going to specify that the state is going to be present. So with
that now done,
if I just happened to write and quits, so let's run the playbook. We'll say
answer
a playbook play three dot YML and to enter give it a moment and we can see here
we've actually
made the change we've created the mount point and we have mounted a device. Now
check this out though.
If I happen to go to my blue box right here, we check the home directory to an WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
If I happen to go to my blue box right here, we check the home directory to an
LS we can actually
see this mount point right here. But watch this if I say an LSBLK dash F, it
appears we actually
have not mounted anything here. You see that this particular device is still
not mounted.
Now this is the point I'm trying to highlight to you. Just check which I
specified for the state.
I specified that the state should be present. Now what does that actually do?
It only specifies
that the device is going to be configured in FS tab but it does not trigger or WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
that the device is going to be configured in FS tab but it does not trigger or
require a mount.
So what we did is we didn't actually mount the device and this is something to
be very aware of.
But what we did do is we did modify the ACFS tab file because check this out
right here.
Here is the device. Here is the mount point and here is the file system. So
what this actually means
is if I happen to now reboot this particular device, I just say it's to do
reboot. When it
reboots because it's particular entry is inside ACFS tab, it suddenly will be
mounted upon the
reboot. It just was not mounted instantaneously. So for open up a terminal and WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
reboot. It just was not mounted instantaneously. So for open up a terminal and
I know say LSBLK
-f once again now that we have rebooted the system, check this out right here.
This particular device
does actually have the correct mount points. So be very careful about
specifying that state
option. Whatever you happen to choose can really modify how the particular
module is going to
behave. Now say for example, I just say pseudo U mounts and I unmount the
particular file once
again or rather the particular device should I say. If I now do an LSBLK -f it WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
again or rather the particular device should I say. If I now do an LSBLK -f it
has been unmounted.
Let me show you what we can do. Let me just make a little modification to the
playbook just for
posterity. If say for example, I didn't want to specify the actual device name,
I actually wanted
to use say for example, a UUID or a label. If I want to use a UUID for example,
what I'm going to do
here is say UUID is equal to and then specify the UUID value. So again, if we
go to the blue box,
LSBLK -f we can take the UUID value right here just copy here and now I can WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
LSBLK -f we can take the UUID value right here just copy here and now I can
paste this in right
here. In fact, before I do anything, let me go back into the XSFS tab file or
just say pseudo vim,
XSFS tab and right now I'll just delete this just so it's no longer here just
for clarity.
So with this now done, we would create the exact same effect. The difference
would be that the UUID
is what you would see within the XSFS tab file and ultimately when we reboot
the same device is
going to be mounted. Now if I want to maybe change the actual behavior right WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
going to be mounted. Now if I want to maybe change the actual behavior right
here and mount it straight
away, then what I want to do is to specify the mounted value and give that to
the state parameter.
So let's try this then, let's make the modification. I'll change the state to
be mounted if I just
write and quit. Let's try running the playbook once again so let's hit enter.
We didn't need to create
the mount point because the directory already exists but we have made a change
on the actual device
for the mounting itself. So let's go back to the blue box. Let's do LSBOK-f.
Look at this right
here. We have straight away mounted the particular device and now if we go into WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
here. We have straight away mounted the particular device and now if we go into
the XSFS tab file,
clearly we can see the mount point right here and this time within the actual
file with actually
reference of device via its UUID.