So friends, in this particular video, what I want to discuss with you is the
user module within Ansible.
Now you will recall having sat the RH CSA examination, we understand that on
Linux systems,
we have the ability to create users and then specify a whole list of associated
attributes.
Things like what type of shell environment should that user get? Should they
get a
born shell? Should they get a bad shell? That type of thing? Should they be
granted some type
of home directory upon the creation of their account? And we also have other WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
of home directory upon the creation of their account? And we also have other
considerations
to recall when we happen to create a user account, say for example, the user is
called John,
then by default they're going to be associated with a primary group known as
John, pretty much
the same as their actual username, but we also have the ability to invoke
secondary groups.
So that means that the user doesn't have to just be a member of one single
group,
we can be a member of multiple groups. So in this particular video, we're going
to
address some of the issues and concerns around creating these particular users WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
address some of the issues and concerns around creating these particular users
with these
specified attributes. So one thing to actually say on that note about the
assignment of groups to a particular user is that when it comes to the actual
creation
of our user accounts, this actually can be handled via the user module in Ans
ible.
I mean, there is no real surprise there is the user module after all. However,
when it comes to
the creation of groups with an Ansible, we actually have a dedicated group
module to handle that
particular task. Now this might seem obvious, but it is worth pointing out for WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
particular task. Now this might seem obvious, but it is worth pointing out for
clarification,
when we want to create a particular user using the user module, then we can
assign the values
such as the username, as well as the shell they're going to have. However, if
we are going to specify
which groups they belong to, well, those groups actually have to exist for the
user module to operate
correctly. Pretty much what I'm suggesting is that you actually use the group
module first to create
all the necessary groups such as you know, group one, group two, group three, WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
all the necessary groups such as you know, group one, group two, group three,
that type of thing.
And once those groups actually exist, then use the user module to specify the
user, say for example,
John, and then with this particular module, you can assign the user John
membership into these
existing groups. So that really is the workflow that we're going to see when we
happen to invoke
the creation of particular groups. So the very first thing that we're going to
do is of course,
go to the documentation. And from that point on, we'll be able to figure out
how to actually use
this particular module or these two particular modules, should I say. Okay, so WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
this particular module or these two particular modules, should I say. Okay, so
let's get going.
So recall, we can actually view the documentation directly via the command line
interface. This
would be the Ansible document. And I can do dash L for a listing. Now, if we
happen to scroll on
down, notice we have our built in group module, which is going to allow us to
add or remove groups
and scrolling on down a little bit further, we have this user module to manage
user accounts.
Now, if you do prefer, by all means, you can use this command line utility. It
's very, very useful
in the examination. But for the purposes of clarity, I just think it's a little WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
in the examination. But for the purposes of clarity, I just think it's a little
bit easier to consume
on the web browser. So that is where I'm going to go just now. So if you just
happened to search
for Ansible, use our module, we can click this top link here in the
documentation for Ansible.
And let me just scroll on a little bit so we can see this module is a part of
Ansible core,
meaning that we don't have to install anything. No surprises there. It is a
built in module after
all. And if we scroll on down, we can see here, this is going to allow us to
manage user accounts
and user attributes. Notice though, if we happen to be also managing Windows WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
and user attributes. Notice though, if we happen to be also managing Windows
system with then
Earth topology, we actually have a separate module for that. We actually have
the Ansible
Windows module. And then the when users are so be aware, this is not going to
work on Windows
based systems. So let's look at the parameters here. Check this one out right
here. This is actually
an important one append. We have a billion value, meaning that we're going to
supply either true
or false. And notice what happens here, it says if we set the value to true, we
're going to add
the user to the groups specified in the groups. Basically, this here is a non WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
the user to the groups specified in the groups. Basically, this here is a non
parameter that we
can supply. Let me just go and show you that just now. So let's just scroll on
down a little bit
further. Check this one right here. It says we have the groups option and
information we supply is a
list of strings. And this is how we supply a list of all the supplementary
groups, which the user is
also a member of. So remember, we just talked about this, a user can be a
member of multiple groups.
But look at the default behavior. By default, the user is going to be removed
from all other
groups. So think about any groups you do not specify within this option, the WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
groups. So think about any groups you do not specify within this option, the
user is going to be
removed from those groups by their omission. Now we can actually override this
behavior by looking
at the parameter we just saw before append when we set the append value to true
. It means that the
user is going to keep the membership to all other existing groups, even the
ones we don't mention.
And any groups we supplies, such as let's say we supply group four, group five,
and group six.
If the user is already a member of group one, two, and three, by setting the WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
If the user is already a member of group one, two, and three, by setting the
value to append,
the user will be a member of group four, five, and six, as well as retaining
their initial
membership to groups of one, two, and three, whereas if we do not specify that
we should append to
these values, we would effectively remove their membership from groups one, two
, and three,
and they would only be a member of groups four, five, and six. That is what we
're talking about
here. As I mentioned earlier, we have the option to specify a user's home
directory upon creation.
We can do so by specifying the path and the home parameter. Now this particular WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
We can do so by specifying the path and the home parameter. Now this particular
parameter is
very, very important. We can tell because it is a require parameter, meaning
that the module will
not operate without this option supplied. And that is the name pretty much we
just have to specify
or provide the name of the user that we want the user module to either create,
remove, or modify.
So this is non-negotiable. And if we just get down a little bit further, we can
also supply a
password for that particular user. We'll talk about that a little bit later on
within this very
skill. And then we come down to the shell option, again, we supply a string WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
skill. And then we come down to the shell option, again, we supply a string
value. And this is going
to allow us to specify the user's shell. So like I say, if perhaps you want to
give the user a
bond shell, which would be bin SH, you can supply this right here, or depending
on the environment,
maybe you want to specify a Z shell. But more commonly, most cases you're going
to be supplying
a bin bash shell. So these are just some of the options for the user module. If
we just go back
to Google, and if you just happened to search for Ansible group module, this
now takes us to
documentation for this particular module. So let's scroll on down. Once again, WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
documentation for this particular module. So let's scroll on down. Once again,
we can see this is
part of Ansible Core. It has a built-in module. We're not going to have to
install it via collection.
And again, the synopsis tells us this is going to allow us to manage the
presence of groups on a
host. Similarly, just like with the user module, if we're dealing with Windows
system with thinner
topology, we would have to use a different module entirely of the Ansible
Windows when
group module. So again, we can specify particular values. We can specify saying
this example here,
the group ID, which is going to be an integer value. Here we have the name WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
the group ID, which is going to be an integer value. Here we have the name
parameter. Once again,
this is going to be a string value. And this is required. Basically, we can't
use a module
without supplying this value. And scrolling on down, we can specify the actual
state that is whether
the group should actually be on the system, or whether it should be removed
from the system. So
basically, we can specify should the state be absent to remove a particular
group, or we can specify
the state that should be present to ensure that that group is valid and present
on the system.
So now that we've seen some of the documentation, let's get hands on by WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
So now that we've seen some of the documentation, let's get hands on by
creating some examples in.
Okay, so let's create a little playbook called play one dot yml. And let's just
go in and edit
this. Let's go into insert mode. Let's have our three hyphens at the top. We're
going to give this
a name. I'll just call this play one testing the user module. Now the host I'm
going to target,
let's target the all groups will target both the yellow box and the blue box,
and are
specify my tasks I wanted to find here. So the first task is going to be use
the user module.
So what's the name of the actual module where we know it's going to be answer WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
So what's the name of the actual module where we know it's going to be answer
able built in
user. And now we're going to specify our particular value. So what was the
required parameter? Well,
if you recall, that was the name parameter, pretty much we're going to have to
supply the name of
the user we want to create. So let's create a user called Fred. Okay, now the
next thing I'm going
to do is I'm going to specify which type of shell environment should Fred have.
So I will say shell.
In this case here, I will just give Fred a born shell. Okay, so a pretty
limited shell. And let's
also specify the user ID. So let's give Fred a value of 1099. Okay, so let's WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
also specify the user ID. So let's give Fred a value of 1099. Okay, so let's
just write and quit.
And all I will do in fact, just before I do this, if I go into the essay pass w
d file,
we can see we have our nugget user or answerable user and our test user. But
notice we do not
have an account for Fred when we run this particular command, that should exist
. Or I suppose I should
more accurately say when we run this particular playbook, it should exist. So
with that said,
let's hit enter. And we are gathering facts. I should probably have set that to
false to speed
things up. But nevertheless, and as we can see here, we have used the user WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
things up. But nevertheless, and as we can see here, we have used the user
module and have a change
on both of our devices. So what we want to now do is to confirm those changes.
So let's go back
here. And if I now cat the same file, look at the very bottom here, we have the
user Fred. We have
Fred's user ID. And we can see that the shell that Fred has is the SH shell.
Now right now Fred
does not actually have a password. Again, we'll talk about that later on. But
if I just say so,
go past wd on Fred's and I type in my admin password. And now I give Freddy
password of WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
password of
like just say Fred one. And I'll also confirm it as Fred one. Now Fred has a
password so we should
be able to substitute user into Fred's. And if I type in Fred one, I can say
who am I? And I can
echo out my shell environment. And we can see here we actually do have a born
shell indeed.
Similarly, if we go to the blue box and cat the exit password file, once again,
then the very bottom, we can indeed see we have creative Fred with the user ID
and we have assigned
a born shell to that account. So now that we understand the very basics of
creating a user with WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
creating a user with
Let's now get hands on with the group module.