So friends, in this particular video, what I want to do is to talk to you about
a very
particular module that we can use when implementing our Ginger 2 templates.
That is the template module.
With that said, let's just check it out.
So you already know what I'm going to do.
Let's go to the big Google machine.
So if you just happened to search for Ansible template module, let's go to this
top link
right here, template of file out to a target host.
So the very first thing to note is that this is part of Ansible Core, meaning
that we do
not have to do any type of additional installation. WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
not have to do any type of additional installation.
This is going to be with us directly out the box.
Now realistically, we can use the short name templates, but preferably I tend
to be very,
very explicit.
And just like with the shell module, for example, I like to say Ansible dot
built in dot template
when using this particular file, or rather using this particular module, should
I say.
Like you see, it's just to avoid conflicting with any other collections.
Okay.
So with that said, let's just scroll on down and see how this actually operates
them.
So as we're going to see when we dig into the actual use of Ginger 2, the WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
So as we're going to see when we dig into the actual use of Ginger 2, the
templates are
going to be processed by the Ginger 2 temperature language.
And if we scroll on down, we come to the actual parameters of play.
Now we see here we actually have this option for block end string, as well as
block start
string.
Notice the actual syntax here.
Okay.
What we actually have here is a curly brace followed by a percentage sign.
Now this is the type of formatting we're going to see when we come to use
Ginger 2.
So just understand that this is the default setting and we can actually use a
different
delimiter if we so wish by specifying particular parameters. WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
delimiter if we so wish by specifying particular parameters.
So whilst we will be using this particular syntax in our Ginger templates, just
understand
we can actually have some variation on this.
Okay.
Now this particular option here is very, very important.
How's important?
Well, we can tell because it says it is required.
What this is actually going to do, it's going to allow to specify the
destination pass pretty
much when we actually render our Ginger 2 templates, we can define where about
we want
the finalize render template to actually be. WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
the finalize render template to actually be.
So what does that actually mean?
Well, imagine you happen to have your Ansible machine right here.
And let's maybe say we are managing three different servers with Ansible and we
want
to push out some type of templateized configurations to these three devices.
Well, where about do we actually want the configurations to go?
Where is the destination?
So let's maybe say we wanted to template out the Etsy host file for each device
.
Well, that would actually be the destination that we would supply here and that
would copy
the configurations we render here into that particular file on this device, the WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
the configurations we render here into that particular file on this device, the
second
device and the third device right here as per the diagram.
So very, very important parameter to understand.
Now scrolling on down here, we come to another very, very important parameter,
the SRC parameter.
This is going to allow us to specify the source in this case.
And once again, we can see here that this is actually a required parameter for
this particular
module.
So using the previous example, if we happen to have our Ansible controller here
and our
three devices that we happen to be managing, if we are modifying the Etsy host WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
three devices that we happen to be managing, if we are modifying the Etsy host
file, that
would be the destination that we specify.
And that is going to be applied to the actual managed devices here.
Whereas the source parameter that actually applies to the Ansible host itself,
what we
are actually referring to is whereabouts the actual gender to template can be
found, the
template that is going to render the configurations that will be pushed to
these destination endpoints.
So if you happen to scroll all the way down to the very bottom here, we can see
some examples
of utilizing a template. WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
of utilizing a template.
Say for example, here we want to write a template for the Etsy file dot conf
configuration file
here.
We see the name of the task, we can see the actual module being used here with
the full
name as specified, we see the source and destination because they happen to be
required.
And notice here, like I say, this is the path to the actual gender template
itself on the
Ansible device.
My templates through dot J2.
Now, this is actually common convention to actually have your own sub folder
for your
templates.
You can call anything you so wish like my templates or as I often just do WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
You can call anything you so wish like my templates or as I often just do
simply just
create a file or rather a folder should I say called templates that is going to
keep
things nice and orderly so that we're not mixing and matching our templates
with our
variable files, that type of thing.
And again, like I said, the destination, we can just supply the path right here
.
Now, we can also specify additional options such as the owner of the file, the
group,
as well as the file permissions right here.
In this case here, we have 644, which should be the opton notation.
But if we go down to the bottom example here, as the source, we render the food
dot J2 file WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
dot J2 file
and copy into the Etsy file dot confell in all the targets.
This time though, the mode is allowing us to specify the file permissions
utilizing some
ball annotation to that obviously as an option to notice that we can also
dynamically pass
in different source configuration files.
And this case here, but actually not hard code in the value, we are calling a
variable
value contingent upon the Ansible operating system family.
This is very, very good when you don't want to be copying the same type of
configuration
to the same type of device. WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
to the same type of device.
You want to render configurations to a Debian based system and use a different
template
for a rail based system.
Utilizing substitution and calling in these variables allows us to dynamically
look up
the correct path for the correct type of operating system in this example.
So those are just some of the bare bones basics about how to utilize this
particular module.
But as you know, the best thing to do is to get hands on.
So the very first thing that we're going to be doing is to build out some
variables
and then begin combining those variables with the template module to actual WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
and then begin combining those variables with the template module to actual
render configurations
utilizing JINJITTER.