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

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