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 a regular expression, in conjunction with the Ansible replace module, to find the DocumentRoot line and modify...