So friends, how about we dive in and begin looking at how we can go about
automating our file system creation on Red Hat Enterprise Linux.
Now as is often the case with Ansible and Linux that are many ways to perform a
particular action, the very first way I want to show you is how we can use a
dedicated file system module to actually perform this particular task.
So what we're going to do as you can probably guess is we're going to go to
the documentation for this particular module and see how we can actually use it
.
So with that said, let's go right there right now. WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
So with that said, let's go right there right now.
So I'll just pull up my browser for a moment.
So if you happen to search for Ansible File System module, if you click this
top
link right here, Community General File System, let's go in.
Now as you can probably expect from the output here, this is not a part of Ans
ible Core,
meaning that if you do not have the Community General Collection,
you're going to have to install it with this particular command, Ansible Galaxy
Collection, install community.general.
Now in my case right here, I already have this, but nevertheless, if you do not
,
just copy here, go to your control node where Ansible is and just paste this WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
just copy here, go to your control node where Ansible is and just paste this
command
and hit enter and you will have access to this particular collection.
Now we can see here the way to use this in a particular playbook via the fully
qualified collection name as to reforms community.general.failsystem.
Now if we just scroll on down a little bit, we can go to the synopsis, which is
very,
very short.
It simply tells us that this module is going to create a file system,
no real surprises there.
So let's go and look at some of the parameters and learn how we can actually
use this.
So scrolling on down to parameters, the very first parameter is the dev WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
So scrolling on down to parameters, the very first parameter is the dev
parameter,
otherwise aliased as device, very, very important.
This here is the required parameter, so we know if we do not supply this
particular
value, we cannot use this particular module.
Now it says here, what we have to do is supply a path.
Now this is going to be the path to the block device or the regular file.
So what am I talking about?
So if we happen to say for example, adding new device into our system, say for
example,
dev, and it might be say SDB or maybe SDC or in my case, the devices that I WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
dev, and it might be say SDB or maybe SDC or in my case, the devices that I
just added
if I go to my blue box, for example here.
If I do pseudo-parted dash L to list my partitions, at the very bottom here we
have
this unrecognized disk, that is dev NVME0N2.
This here in my case is going to be the value that I will provide to the dev
parameter
with this particular module.
But again, depending on your own system, this might be a different value to
just keep that
in mind. WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
in mind.
Now we have other options, we can specify the force option which is going to
take a billion
value if we specify true.
And this is going to allow us to create a new file system on devices that
already have
a file system.
Pretty much if we want to force the creation of a file system, we can overwrite
an existing
one fairly straightforward.
Notice if we don't provide this value, the default as specified here is going
to be
false so we will not automatically overwrite existing file systems.
Which in my opinion is a pretty good and safe default.
Now, let's go down to this part right here, this is obviously very important, WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
Now, let's go down to this part right here, this is obviously very important,
FS type.
What we're going to do here is to specify a string value.
And pretty much this is going to be the file system type that we want to create
.
Now scrolling on down here are our choices.
Now we happen to mention in the previous video some of the different file
systems that we
can use, we can see EXD2 which is very very outdated, unlikely you're going to
use this.
Similarly, EXD3 a little bit more modern but more commonly you're much more
likely to
see things like EXD4 or perhaps like I say in the case of Red Hat based systems WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
see things like EXD4 or perhaps like I say in the case of Red Hat based systems
, XFS.
Now of course depending on the system that you happen to be using, maybe you
are dealing
with a logical volume management system.
Remember this is LVM which we talked about in a previous scale, you can specify
that
as a file system.
But we also have other options such as swap space, VFA, that type of thing.
Whatever as you want to choose, we specify that particular value into the FS
type parameter.
Now this parameter here opts.
We can see here this is going to take a string value and this is pretty much a WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
We can see here this is going to take a string value and this is pretty much a
list of options
that you want to pass to the MKFS command.
Now recall in the previous video we learned that this is the particular command
that is
going to make a file system.
So if you want to specify particular options that you ordinarily would with
this particular
command you can pass them in the Red Live Viewless parameter.
Similarly if you want to perhaps resize a file system, we have the resize FS
option.
Once again this is going to take a billion value and if we set the value to
true, we
are going to grow the file system into the existing space. WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
are going to grow the file system into the existing space.
Notice though if we happen to use an XFS file system, we can only grow if that
file system
happens to be mounted.
So a little bit of a difference depending on the file system in use.
Now we also have this state option here again going to take a string as an
option.
We can specify the option of present which is the default and this is going to
allow
us to create a file system if it doesn't already exist.
Whereas if we specify the file system should be absent, the file system
signatures are
going to be wiped if it contains a file system. WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
going to be wiped if it contains a file system.
Rolling on down we also have the universal unique identifier option.
We can specify a string value and pretty much the string value we are going to
present here
is simply the file systems UUID fairly straightforward.
So with that now said, let's take some of this information and begin
constructing our
own playbook here.
What I will do here is I will create a playbook, let's just call this play1YML
and I am going
to insert mode to have my three hyphens at the top and I will give this a play
book a
name and just say play1.
I will just say testing the file system module. WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
I will just say testing the file system module.
So who am I going to target?
Let's just target, let's maybe say the blue box device.
Now in this case here I am going to set gather facts to false because it is not
necessary
to gather facts and it is just going to slow us down.
So let's just do that and now I will define my tasks that I want to create here
.
So the first task is going to have a name, we will just call this task1 and let
's just
say creating ext4 file system.
Now think about what we are going to use here.
We want to use the community.general.file system module. WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
We want to use the community.general.file system module.
Now inside of here we absolutely have to supply the dev parameter and this is
going to point
to the block device you want to target.
Now recall on my system the device that I happened to add was /dev nvm e 0n2.
Now again this here is a part whereby it might be different on your system.
You might see sdb or stc or something like that whatever it may be you want to
put in
that value right here.
The next thing I want to do is I want to specify the file system that I want to WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
The next thing I want to do is I want to specify the file system that I want to
create.
So I can say fs type and like I said in my case here one of the options
available is
going to be ext4 so that is the value that I am going to supply.
And if I so wish that I could add an additional options but for now let's keep
things really
quite simple.
So let's just write this right here and before I do this notice we have our
disk right here.
So all I will say is Ansible Playbook Play1.yml and to insert give it a moment
to run and we
can see a change has been made if we go to a device to confirm let's see what WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
can see a change has been made if we go to a device to confirm let's see what
we get.
So I will just say so though parted dash L and look at what we have right here
here
is the device that we just targeted and check this out right here on partition
number 1
we have this file system for ext4.
Whereas if I go to my playbook once again let's change file system type change
it to
state and I'll just specify that I want the state to be absent on this
particular device.
So let's try to rerun the playbook once again hit enter.
So whilst the heading still says we are creating an ext4 file system in reality WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
So whilst the heading still says we are creating an ext4 file system in reality
what we just
did there was remove it.
So if I happen to add up and rerun the same command again check this out right
here we
have now removed that particular information.
So what I am going to do here just briefly is if I go in and modify the
playbook once
again let's maybe change this to an XFS file system and I'll change FS type to
be XFS let's
just save this and now let's rerun the playbook once again.
To know we have a change we go back to the blue box arrow up and to enter we
now have
a partition formatted with the XFS file system. WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
a partition formatted with the XFS file system.