Templating is a powerful tool that we can add to our Ansible arsenal, enabling us to set up some interesting configurations quickly. This lab will help us practice with that tool.
Learning Objectives
Successfully complete this lab by achieving the following learning objectives:
- Write a Template to Replace the Document Root in httpd.conf and Any Other Configurations Required
Using the provided httpd.template, replace all occurences of /var/www/ with
{{ variable_name}} – similar to the following. This will let us update the directory with the use of a variable:<Directory /> AllowOverride none Require all denied </Directory> DocumentRoot "{{ webdir }}html" <Directory "{{ webdir }}"> AllowOverride None Require all granted </Directory>
Note that there are more places
/var/www
needs to be changed to{{ variable name }}
, these are just two.- Write a Playbook to Deploy the Template to the webserver Group
Your playbook should look similar to this:
--- - name: Template playbook hosts: webservers become: yes vars: webdir: '/opt/' tasks: - name: Deploy the web template template: src: /root/httpd.template dest: /etc/httpd/conf/httpd.conf