From the course: Ansible for Automation Essential Training: Advanced Playbooks, Roles, and Diverse Hosts
Unlock this course with a free trial
Join today to access over 25,300 courses taught by industry experts.
Exploring templates - Ansible Tutorial
From the course: Ansible for Automation Essential Training: Advanced Playbooks, Roles, and Diverse Hosts
Exploring templates
- [Instructor] Templates can be quite handy in many areas. They are great at customizing configuration files, building HTML pages dynamically, or even the likes of network device configurations. Ansible uses the Jinja2 templating engine. Going through all the options available would be a course of its own, but in short, you can do variable replacement, loops, conditionals, and data manipulation of all kinds. For my demo here, I've duplicated the playbook from the last section where I installed the NGINX web server. I'm going to configure the web server and the index.html page using templates. I'm going to add two variables in the var section that I'll be using below, in, and with my templates. I'll skip to the end of the playbook and start by pasting in a task that will use the file module to create a directory to store my web files. I'll now use the template module to build and install the index.html file. Name, because I always give it a name. Add index.html to web server directory.…
Contents
-
-
-
(Locked)
Installing collections2m 20s
-
Construct a simple playbook4m 19s
-
(Locked)
Using variables5m 7s
-
(Locked)
Using loops2m 45s
-
(Locked)
Adding conditionals4m 57s
-
(Locked)
Utilizing blocks3m 49s
-
(Locked)
Exploring templates4m 29s
-
(Locked)
Discovering handlers2m 23s
-
(Locked)
Using tags2m 53s
-
(Locked)
Testing plays with check mode2m 15s
-
(Locked)
Conditional failure with assert2m 20s
-
(Locked)
Failure and change control2m 32s
-
(Locked)
Nesting loops3m 29s
-
(Locked)
Creating dynamic inventory files3m 7s
-
(Locked)
Challenge: Create a complex playbook1m 17s
-
Solution: Verify the complex playbook2m 52s
-
(Locked)
-
-
-
-