From the course: Ansible Essential Training
Unlock the full course today
Join today to access over 23,200 courses taught by industry experts.
Using templates - Ansible Tutorial
From the course: Ansible Essential Training
Using templates
- [Instructor] Templates tend to be a major aspect of configuration management and automation tools like Ansible. So, it's no big surprise that Ansible is ready for templates and their usage, thanks to built in support for Jinja2. Jinja2 is a popular templating language for Python developers. So, let's take a look at a simple example here, a simple, but very fun example. So, in my home directory here, notice I have created a template named Jinja2.J2. So, it must have that .J2 extension, but you can name the template whatever you like. So, let's take a look at that. If we go in and look at the Jinja2 template, we are going to see that it is very simple. It says, a message from your node and then the variable of inventory underscore host name that it can take from the facts on the target system. And then it says today's message and it gives a web server message. This is a variable that we are going to actually define…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
(Locked)
Using host groups4m 31s
-
(Locked)
Using tags4m 27s
-
(Locked)
Running tasks against localhost5m 25s
-
(Locked)
Using the command line to control execution5m 2s
-
(Locked)
Specifying variables in the inventory file5m 51s
-
(Locked)
Creating dynamic inventory files7m 5s
-
(Locked)
Using templates6m 15s
-
(Locked)
Conditional execution4m 25s
-
(Locked)
Using loops7m 45s
-
(Locked)
Testing plays with check mode3m 27s
-
(Locked)
-
-
-
-
-