Understanding Ansible templates

A common automation requirement is to set a value in a configuration file, or even to deploy a new configuration file, based on some given parameters. Ansible provides modules that can perform similar functions to the venerable sed and awk utilities, and of course, these are valid ways to modify an existing configuration file. Let's suppose we have a small Apache virtual host configuration file, containing the following code:

<VirtualHost *:80>    DocumentRoot "/var/www/automation"    ServerName www.example.com</VirtualHost>

We want to deploy this configuration, but customize the DocumentRoot parameter for each host. Naturally, we could just deploy the preceding file, exactly as it is, to every host, and then use ...

Get Hands-On Enterprise Automation on Linux now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.