In this video, we will write a playbook that will allow us to change file permission of a file at a
remote client.
So the first thing we have to do is we'll log into our Linux client, which is our remote client, and
we'll create a dummy file and we'll call it Linux two in home Excel Directory.
You could create it anywhere you want, but then you have to specify the right location.
All right, so once file is created, let's come back to our control node and we'll start writing our
YAML file and name it file permissions yaml.
All right.
Once we are in the YAML file editor, what's the first thing we do?
We define a dash, dash, dash, so we know that it's YAML file.
Then we have to put down the name.
That's the name of our playbook change file permissions or if you are doing additional task, then you
put down a summary of that tasks.
All right.
So host, you already know anything that we have in our slash at see ansible host file all of those
hosts will be.
Part of this change.
So be putting down all.
Then we have an empty line and then we defining the task.
The task again is indented, indented and it's vertically aligned where name and hostess.
And so what's the task?
The task name is changing file permissions or file permissions only.
All right, then we will use the module, and the module is file.
In this case, yes, we are dealing with file systems, so we will use the file module.
All right.
So now the path the path where the file location is, this is the location of the file that we have
to modify.
All right.
So we have to use mod then.
And the mod we could use letters for defining a plus w meaning we want the file to have right permission
for everyone and that A stands for all.
You can also use numerical digits to define the mode as well.
So either digits or letters, whichever you are comfortable with, and that's where you define the permission.
Once that is done, then you run the playbook.
And don't forget all your modules and its options are available in docs dot dot com, slash ansible,
the version and the modules.
You get the list of all the modules that are available out of the box for you.
All right.
Let's get right into our Linux boxes and let's start writing the playbook.
The very first box that we'll get in is our client.
And I am logged in as root.
Already you can log in as you saw.
It doesn't really matter.
I am in temp directory.
Who am I?
Am logged in as Ruth.
Let's go to home iocl and let's touch Linux to.
All right, let's see the permissions that are given to Linux two you see right here.
RW Dash, ah dash are dash, dash.
So it means everyone can read it, but only root can write to it.
So when we run this playbook, it should give right permissions.
Right.
All right.
So that's what it is.
We create it.
Now let's go to our control node and here is our control node.
Let's log in as route and I'm already in playbooks.
Who am I?
Am logged in as a root.
Excellent.
So when I'm file permission dot yaml.
Dash, dash.
Dash, dash and dash.
Name off the playbook or the play.
Change.
File permissions.
All right.
Host you could put local hosts if you are putting if you're making a change on this local host or simply
put a space tasks and then name.
Of that specific task permission.
All right.
The file is the module.
And once the module is defined, it will automatically advance or give you the right indentation to
put the parameters.
The path path is home is all.
And here is the file.
Linux two.
And what do you want to change its permission to all should have a write permission.
All right, that's good.
Let's save the file.
Playbook is done now let's run it Ansible dash playbook file permission yaml.
All right so it will go through the play change file permission right here to all here is our client
and the client tasks changed and okay to and right here says changed meaning what you have asked has
been completed.
Beautiful.
Now to confirm that on our client will go to our client machine right here.
This was the permission.
And when we do ls minus l t again.
Now, this is the new permissions that are given to this file through our playbook.
All right, so now you'll learn how you could change permissions using the file module.
You could do a lot of other things, the permissions, the ownership of a file to this module.