Deleting old releases from rails app server using puppet


You would like to automatically delete old releases from your rails app server using a puppet crontab resource.


Add the following to your modules/crontab/manifests/init.pp file and modify some of the values to what you need:

You should need to change the following:

/var/www/your/path/to/ror/app/ to your application’s release path
-gt 10 this is the number of minimum old releases you want to keep
-mtime +14 releases older than 14 days are deleted


There is chance that when you do not calculate the frequency of the releases right the above script can potentially delete all of your releases, so you end up with no releases 🙁

A better solution to keep the -n number of releases (based on the solution from here:

and the explanation of each step:

  • find /var/www/your/path/to/ror/app/* -maxdepth 0 -type d -printf ‘%T@ %p\n’ find all the directories (-maxdepth 0 -type d) in the search path (/var/www/your/path/to/ror/app/*) excluding the . and .. directories (/*) and add to them the time information (‘%T %p\n’)
  • sort -nr sort them in numeric and reverse order – newer first, oldest last
  • tail -n+6 keep only the first 5 directories, starting from line 6 (tail -n+6)
  • cut -f 2- -d ” “ Remove the first field (ie the date information) keeping the file from the second field using the space as the delimiter (-d ” “)
  • xargs -i rm -rf {} Pass the rm -rf command to delete the directory for each line produced in the previous steps

So the puppet script should be as follows (including the escape characters \ for the % and the additional \):

Error in AWS when trying to include puppet modules (Error: Could not find class apache2 for …)


You are trying to work with puppet modules in AWS, after installing puppet as a gem, but when you try to put the modules and manifests outside the main manifests/site.pp file you get an error similar to following:


Create a file for the puppet configuration in /etc/puppet/puppet.conf and add the paths to your own manifests and modules, like :

and add your paths:

Can’t install RMagick 2.13.1. Can’t find Magick-config


You are trying to install rmagick in an Ubuntu 12.04 virtual box, but you get the following error:


Make sure you install both the imagemagick and the libmagickwand-dev packages with either apt-get :

or in a puppet script as:

sudo: puppet: command not found – when trying to use puppet with rvm in aws

When trying to use the

command in a aws instance to follow the instruction from ‘Deploying Rails’, the following error complains that the puppet command is not found, like:

After some searching and having a look at the blog post here and using the rvm notes in the aws instance and looking at this:

It seems that for security reason the sudo command resets the path in the system.

You can actually see that this the case by running the command to display the path of the normal user:

and the corresponding one for the sudo:

So a workaround to make it work is to add your group into the exemptions group in the visudo file, which means editing the visudo file:

and adding the group that your user you are working with belongs to:

Writing a Passenger Module for Puppet – Vagrant

Following the steps described in the “Deploying Rails Applications” book and using the currently latest puppet installation described here, the actual puppet files had to be modified slightly in order to make it work as expected.

The main issues requiring the changes were as follow:

  • System wide rvm installation – different paths, and the use of the rvmsudo command instead of sudo
  • Use of latest puppet gem (3.0.1) – ruby 1.9.3 is supported
  • Use of Debian/Ubuntu system – different way of configuring passenger with apache2

So the full file for the passenger module (puppet/modules/passenger/manifests/init.pp) is:

Going through the file one of the first things to notice is the declaration about the “apache2-prefork-dev” package installation

The reason for this package, is that when trying to compile the passenger apache module (passenger-install-apache2-module), the script will complain that the following packages are missing:

By installing the first of the packages (apache2-prefork-dev) the other two are installed automatically as dependencies.

NOTE In trying to install it in an Ubuntu AMI image in AWS EC2 there is also an additional package requirement because the installer complains about:

So there is the additional package added as:

Further down there are two file resources named “passenger_conf” and “passenger_load”.
Looking at the structure in debian for the apache2 configuration it seems that apache2 in debian needs two different files for each module that can be loaded one with named as module.conf and another as module.load to be placed into /etc/apache2/mods-available.

So we can create these two files and placed them in the files folder, as:


and, puppet/modules/passenger/files/passenger.load

Which you can actually see if you compile manually the passenger apache2 module as they are described in the output on successful compilation:

Finally the last section of the init.pp file enables the passenger module with the a2enmod apache command:

A couple of useful apache2 commands when testing are:

  • To test what modules are availble for loading: If run after creating the two passenger files passenger.conf and passenger.load, then the passenger module should appear in the list
  • To see the currently enabled modules: Which again if it is run after the passenger modules has been enabled with a2enmod passenger then it should show an entry with

Could not find puppet (>= 0) amongst [] (Gem::LoadError)


When you try to apply the puppet configuration into a vagrant box and using systemwide rvm installation (if you follow the instructions here), you have the following error:


Use rvmsudo instead of sudo to make sure that the paths are correct: