Introduction to Ansible Transcripts
Chapter: Data
Lecture: What are Templates?

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Variables in our playbooks are useful
0:02 for more than just customizing our tasks and roles.
0:05 We can also use them to create output files using templates.
0:08 Templates are Jinja2 files that contain boilerplate text
0:12 that you combine with variables to produce certain output.
0:14 For example, if you want to create a configuration file
0:16 for your Nginx web server
0:18 if you want to configure a Postgres database
0:21 to lock it down against unauthorized access
0:23 or if you just want to have text file
0:25 with instructions that are customized to each server
0:27 so that if someone logs in
0:28 they'll understand more about the server
0:30 when they read that file.
0:31 As always it helps to take a look an example.
0:33 So here's what we're going to do in this video
0:35 to learn how to use templates.
0:36 We already have the following playbook.
0:38 This is our first playbook
0:39 and we're going to add a couple of new files.
0:40 First one is going to be right template
0:42 which will have a new task using the template module
0:45 to output a template onto a remote server.
0:47 And then we have our template itself
0:48 which will be under the templates directory
0:50 which is a peer of the tasks directory in a role.
0:53 So we separate out our templates from our tasks
0:56 we can reuse the templates across different tasks
0:59 if we want to.
1:00 We typically use the .j2 extension for templates
1:03 because they're in the Jinja2 template engine format.
1:06 However that's not required.
1:07 The files can be named whatever you want.
1:09 I'll use j2 in all these videos for clarity.
1:11 All right, let's add these files to our playbook.