So friends in the previous nugget we learned that we could create our own
Ansible roles. What we would have to do though is to create them according to a
very specific
directory structure. That structure is what we're going to talk about right now
. So the first thing
to state about this particular directory structure is that the top level folder
, i.e. the roots of
the directory structure, that particular folder is going to be the name of the
role itself. And
it's going to be this name that you reference in other playbooks when you want WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
it's going to be this name that you reference in other playbooks when you want
to call that
particular role. So let's maybe say you created a whole bunch of different
tasks that we're going
to maybe perhaps do some DNS updates. Okay. Now like you say this is something
you do pretty
regularly, fairly complex. So you wrap it up into a role and this is what it's
called DNS
underscore updates. Because this is what is going to be referenced in the
actual playbook because
that will be the name of the role. As such at the top level directory, I even
would do it an MKD
if we happen to create this manually, you would actually use that very
particular naming convention, WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
particular naming convention,
the name of the role itself. And inside of that particular directory would be
all of the subfolders
necessary. Now I just referenced that we could actually create this directory
structure manually,
but quite honestly, this is not the way I happen to do this. The good news as
we're going to learn
is that Ansible actually has a very particular utility that is going to allow
us to automatically
generate the directory structure. So pretty much this will give us a nice
little template and we
can basically modify things as we need. One thing you will notice though is WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
can basically modify things as we need. One thing you will notice though is
that when we automatically
generate the directory structure is going to give you all the structure that
you may possibly need,
meaning that if you happen to create as what we're going to do a rather simple
role, we may actually
have many unused directories. But hey, quite honestly, that is a trade off I'm
willing to take. So in
my humble opinion, this is definitely the easiest way to get us going. So we
know the top level
directory is going to be the name of the role. What then is actually going to
be the subfolders? WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
be the subfolders?
Well, to answer that question, why don't we just automatically generate the
directory structure
and talk about what we find. So recall in the previous video, I happened to
mention a type of
marketplace for Ansible roles whereby you can get the roles created by more
experienced community
members. That particular place happened to be called Ansible Galaxy. And for
clarity, if you so wish,
you can absolutely publish your own roles to this particular market. But well,
this is a kind of
online repository for Ansible roles. This is also the actual command that we're
going to use to WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
going to use to
generate a role structure. So check this out. I'm going to say Ansible hyphen
galaxy. And then I
will say a net for initialize and now I will give the name of the role that I
want to create. So
again, this could be absolutely any name you so wish very often a good idea
would be to have a
descriptive name. So maybe you would call the role create users if the whole
purpose was to create
user accounts that type of thing. But in this case here, I will just call the
role CBT example.
Okay. So if I hit enter here, notice it says the role CBT underscore example WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
Okay. So if I hit enter here, notice it says the role CBT underscore example
was created successfully.
So if I now do an LS, here we can see the actual directory structure CBT
example. Now, if I happen
to say tree on that particular directory and to enter, we see all of the child
subfolders of this
directory, as well as a whole bunch of files. So let's work from top to bottom
then, shall we?
So at the very top here, we can see this folder called defaults. And inside of
this folder, we have
a file called main dot YML. Now the whole purpose of this particular folder WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
a file called main dot YML. Now the whole purpose of this particular folder
here is to hold well,
no surprises, default values. But what default values are we talking about? We
're actually talking
about default variable values that are going to be used within the role pretty
much you can
conceptualize this as having some type of sensible default values. So for
someone who is using the
role, if they don't specify another variable of their own, they will actually
inherit the defaults
that you have set for them. So the whole point to note here is that these are
very possibly and WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
very possibly and
almost even probably going to be overwritten in some forum. That really has the
whole purpose of
that particular file within the defaults folder. Now the next one we actually
see here is one
folder called files. Okay, now right now, as we can see, there is nothing
actually inside of this
directory. It's just completely empty. The whole purpose therefore of this
particular directory
is that it is a place that you can house your static files that are going to be
used by the
tasks within the role. So what's going to be saying here is your Ansible
control mode right here.
Let me just draw this out. And let's maybe have a managed device here. So it's WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
Let me just draw this out. And let's maybe have a managed device here. So it's
a device one.
And let's say device number two, again, there could be many more devices you
happen to be managing.
And suppose you happen to have a file that exists on the Ansible control mode,
and you want to be
able to push that particular file to the managed nodes over here. Okay, that
static file that exists
on the control node that you want to be present on the targets when you are
using roles, the place
whereby you would define that particular file would be in that files folder.
And in fact, this
is something that Ansible is going to expect. So when you happen to define a WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
is something that Ansible is going to expect. So when you happen to define a
particular file in
this particular folder, when using a role, you don't actually have to give the
absolute path to
locate that particular file. And did instead, Ansible, like I say, is going to
expect that
file to be in that folder and it will automatically check for its existence
there. So basically,
you can just put the file in that particular folder and just reference the file
name itself.
Now the next one here is something called handlers. And we can see we actually
have a main.YML
file within that directory. Now we actually haven't talked about handlers quite WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
file within that directory. Now we actually haven't talked about handlers quite
just yet.
We'll get to that in an upcoming skill. But as a high level overview, pretty
much,
it's a special type of Ansible task that will actually execute depending on the
outcome of
another Ansible task, basically when a particular condition has been met. Again
, like I say,
we'll get to look at those in more detail later on within this course. Then we
come to the next
directory, which is the meta directory. And again, inside of that particular
file, we can see we
have a main.YML. The purpose of this particular file is really well just to WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
have a main.YML. The purpose of this particular file is really well just to
specify the metadata
associated with the role. So the type of thing that you would specify would be
perhaps who actually
authored the role, what was the date and which it was created, what type of
licensing do you
have for this particular role? Is it free for anyone to use? Maybe you want to
specify the
particular dependencies that have to be installed in order for the role to
greatly operate. All of
that you can define in that main.YML file within the meta directory. Now the
next
one we come to is the readme.md. This is a markdown file. Now if you happen to WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
one we come to is the readme.md. This is a markdown file. Now if you happen to
have experience with
version control and something known as get or get up, you will probably
recognize this particular
file readme as a kind of instruction about how to use the particular utility.
So in this case here,
if you want to tell people how to actually use the role, what its purpose is,
how they should
modify particular values, as well as what they shouldn't use the role for, you
would specify
all of those instructions inside of the readme markdown file. Now the next one,
this one is WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
this one is
probably very, very recognizable. This is the tasks folder and inside of the
task folder,
once again, we have a main.YML file. Now the purpose of this particular file,
you guessed it.
This is where you define the tasks that the role is going to perform. So really
, this particular
folder is very, very important. It's one of the core components of the Ansible
role itself. We'll
definitely get to see this later on within this particular skill. Next, we come
to a directory
known as templates. Now you might have a good idea what this one is all about. WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
known as templates. Now you might have a good idea what this one is all about.
We just discussed
templates in the previous skill. This is where we could specify our Ginger 2
templates, which
would be used to effectively render configurations that we would like to push
onto our target devices.
So maybe you want to perhaps templatize your, oh I don't know, let's say, etsy
resolve.conf
configuration file, because imagine in this particular role, we're going to be
doing some type of
DNS config. Where are you going to put that particular template file? You're
going to put it
directly within this particular folder right here. Now one thing to note is WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
directly within this particular folder right here. Now one thing to note is
that if we happen to do
an LS right now, notice we already have a templates directory here. That's a
lowercase t. This is
where we created our prior Ansible templates. Now when we happen to utilize a
role called within a
playbook, this is not the folder that the role is going to look into. The role
is going to look into
this particular one which is housed, like I said again inside of that top level
directory, the name
of the role itself. So just do not get that confused. The next thing we come to WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
of the role itself. So just do not get that confused. The next thing we come to
is the tests
folder and inside of here, we can actually see we have two particular files.
One is called
inventory and the other one is called test.yml. Now this one might seem a
little bit peculiar. Why
do we have a file called inventory? After all, we already have an Ansible
inventory defined.
But the whole purpose of this particular folder here is to run tests. So inside
of the test.yml
file, this is where you would define all of your tests. But think about it. If
you're going to be
testing things out, is it a very smart idea to test out things that might WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
testing things out, is it a very smart idea to test out things that might
happen to break
against your real live production network? The real servers that your entire
workforce is
relying upon? Absolutely not. So in this case here, we are providing a second
inventory which is going
to be comprised of a whole bunch of mock devices, pretty much maybe some
virtual machines, whatever
it may be, somewhere whereby we can safely test out these new conflicts as the
configuration going
to be rendered correctly, as the status of the service going to be as expected. WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
to be rendered correctly, as the status of the service going to be as expected.
The best way to
test that out is against a test network. That is the whole purpose of that
inventory file.
And then lastly, we come to this varsity rate to the inside of here. Once again
, we have a main
dot yaml file. And this is really quite similar to the very first directory we
talked about. The
name itself is giving us a little bit of a hints. This is where we define our
variable values. Now,
the difference here is that this is where we should define our specific values,
the values that we
would like to use if the default values do not suffice. Basically, if you want WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
would like to use if the default values do not suffice. Basically, if you want
to override the
defaults, we want to define those values inside of this particular file right
here. And they will
be treated with a higher priority by Ansible if there happens to be a conflict
with anything in
the defaults folder. So I know that was a lot of information to get to within
this particular
video. But really, that is everything that we have to know about the directory
structure of the
Ansible role. With that said, how about we begin creating our very first Ans
ible role and well,
that's what we're doing in the very next video. WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
that's what we're doing in the very next video.