In this video, we are going to check a file or a directory status that whether that file or directory
exists and what are the attributes associated with the file.
So the very first thing is we will go into our control node and we will create a new YAML file, we'll
name it check fs fs for file status YAML file.
Okay.
And let's see how we are going to define our YAML file.
What are the things we need to write it?
So first thing is we need to define that it's a GMO file and then we have to put in dash, dash, dash,
then the name of the entire Playbook file status module.
Of course you could name it anything that you want.
The Host Where is it going to run it against?
It's going to run at this time.
We'll run it against our local host.
You can put it all as well.
And as you know, when you put all, it will go to your host file, which is at sea as well, host file
and whatever you have defined in that host.
Well, it will run it against those clients.
All right.
Moving down task, what do you want to run?
The name of the task is check, file, status and attributes and the module that we will use to check
that it's called STAT.
All right.
So this is the stat module.
And now where is the path?
Where is the path of that file or directory?
So we'll define path and path at see.
Host It's just a random file that I picked.
You could pick anyone where you're running your check against.
All right, so this is the location.
And then you have to specify the registration.
Like once the result comes back, you have to hold it somewhere because you cannot just put a stat module
and it will check the status and show it on your screen.
So in order to print that on your screen, you have to use the message, the debug module.
So the first thing is registered, put that output that you get from the stat into some kind of container
and we are registering that or outputting that to an RFS container.
I just picked this a two letter word.
You could pick any word you of your choice.
So then we will use this debug module.
So again we'll specify the name.
Now show result since you already did the stat on that Etsy host and we put it into the FS container
now show that FS container so we'll use debug module and the debug module will have this is the module
to print and the message will be file attributes and then we are going to show the result of our FS
container.
All right.
And then basically we'll run the playbook and the playbook, as you know, the command will be Ansible
Dash Playbook space, the name of your YAML file or the playbook.
All right, so let's go to our control node and let's run this playbook or let's create this playbook.
So I have my node right here.
I'm going to log in as root.
All right.
I am an etsy sorry slash home directory.
I am logged in as who?
I am I am logged in as root.
Okay.
So I'll go into Etsy and Sybil playbook.
That's where I'm keeping all my playbooks.
All right.
Here.
I have already created this checked fs yaml file so we could save some time.
So you could write as I have written here.
Or you could get that file which I have already uploaded in the in the handouts.
So anyway, so let me go over them that check fs yaml and you'll see right here.
The very first thing is we define that it's a YAML file dash, dash, dash name or run stat module or
files that module host we are running it against a local host.
Then the tasks just like the what I have on the PowerPoint slide, the name check file status and attributes.
All right.
And the module you're using, it's a stat module just like we have a copy module, move module just
to check the status of a file attributes.
We use this stat our path, of course.
Where is that file that you want to stat?
And once the result comes back, we are going to register that or put that result into as a temporary
container.
And for that we have to use it register parameters.
All right.
And we are defining that variable or that container is FS are I then show values or show result doesn't
matter what you choose.
The debug is the module and the message file attributes and then read that container.
All right, beautiful.
Now let's go ahead and save it.
And now it's time to run that playbook.
Ansible.
Daesh playbook and name of that playbook.
That e-mail hit Enter.
All right.
Running stat module as you have it here running stat module gathering facts against local host perfect
check file status and attributes.
This is the name of the task check, file, status and attributes All right against local host perfect
now the message right here show what you got from the stat and then right here the message file attributes
right here file attributes.
Perfect.
And these are the attributes it has.
It has exist equal true.
Which means the file is there perfect the passes as the host.
The mod deserves the permission of that ATC host file.
It has all the all the other information wherever you see false meaning that it does not have that.
So if you notice, does it have a link?
It says no, it's not a link.
So that's why it's false.
Uidai is zero.
Group ID is zero because it's owned by root.
I know number is you, I know a number.
And then see time and time when it was created.
These are all the information that you will get when you would actually run stat or or simply run ls
on the command and you get some of the properties or attributes of a file.
So the basic purpose of this video is to check if the file exists and of course to see what are the
attributes of that file.
You would need that in order to run certain commands, because many times you would run a script against
a file.
But of course, before you run that or execute any script, you need to first make sure it has the attributes
or file exist.
And you could run certain commands based on the result or attributes.
You get it back.