Introduction to Ansible Transcripts
Lecture: What are Templates?
0:00 Variables in our playbooks are useful for more than just customizing our tasks and roles. We can also use them to create output files using templates.
0:09 Templates are Jinja2 files that contain boilerplate text that you combine with variables to produce certain output.
0:15 For example, if you want to create a configuration file for your Nginx web server if you want to configure a Postgres database
0:22 to lock it down against unauthorized access or if you just want to have text file with instructions that are customized to each server
0:28 so that if someone logs in they'll understand more about the server when they read that file. As always it helps to take a look an example.
0:34 So here's what we're going to do in this video to learn how to use templates. We already have the following playbook. This is our first playbook
0:40 and we're going to add a couple of new files. First one is going to be right template which will have a new task using the template module
0:46 to output a template onto a remote server. And then we have our template itself which will be under the templates directory
0:51 which is a peer of the tasks directory in a role. So we separate out our templates from our tasks we can reuse the templates across different tasks
1:00 if we want to. We typically use the .j2 extension for templates because they're in the Jinja2 template engine format. However that's not required.
1:08 The files can be named whatever you want. I'll use j2 in all these videos for clarity. All right, let's add these files to our playbook.