
Recently, I was asked to enable mod_rewrite for Apache on our webservers, which are controlled by the sexy puppet master server. I did a quick google to see if anyone had any recipes published. On the puppet wiki there is a recipe for Apache on Etch, but their module portion installs Apache modules. In the case of mod_rewrite it comes with Apache2 so it doesn’t need to be as complicated as they suggest.
My solution is as close to a “one liner” as it gets in puppet. You just check to see if the symlink for the loaded module exists and if it doesn’t, run
a2enmod. Of course it’ll double check to make sure Apache gets restarted too.
define apache::loadmodule () { exec { "/usr/sbin/a2enmod $name" : unless => "/bin/readlink -e /etc/apache2/mods-enabled/${name}.load", notify => Service[apache2] } }
Call it with apache::loadmodule{"rewrite": }
and you’re good to go. You do need to double check that you use the .load file name from /etc/apache2/mods-available/ . In my example it is ‘rewrite’ for ‘mod_rewrite’. You can also create a recipe to disable the module with a2dismod, should you find yourself needing to disable a lot of modules.