Skip to content
This repository

Recipes allow you to execute custom scripts, similar to callbacks. Unlike callbacks, each recipe is a standalone file to allow for sharing and reuse. All recipes are stored in the recipes directory.

Recipes can be run for a specific machine, a role or all machines:

user "somebody"
ruby "1.9.3"
role :master, recipes: %w(setup_master.rb)
server "one", role: :master, recipes: %w(install_nginx_via_passenger.rb)
recipes %w(do_custom_stuff.rb)

Recipes come in two distinct flavors:

  1. Ruby scripts - Any recipe ending in .rb is run as a Ruby script. The advantage of recipes written in Ruby is that they get eval'ed and have access to the Teleport::Util module for conveniently executing commands.
  2. Executable - Otherwise, the recipe is assumed to be a standalone executable. These are usually bash scripts, but you are free to use any executable script.

Example - Nginx w/ Passenger

A sample recipe for installing nginx via passenger (requires the passenger gem to be installed, see how to install system-wide gems) could look like the following:

recipes/install_passenger.sh

#!/bin/bash
set -eu                                                 # bail on errors
passenger-install-nginx-module --auto --auto-download   # install without prompting
update-rc.d nginx defaults                              # activate autostart
service nginx restart                                   # restart nginx

recipes/install_passenger.rb

version_gem = gem_version("passenger")
version_installed = `passenger-config --version`.strip

if !version_gem
  warn "Passenger is not installed. Please add it to your Gemfile."
elsif version_installed == version_gem.to_s
  banner "Passenger #{version_installed} is already installed"
else
  banner "Installing Nginx via Passenger (installed: #{version_installed}, gem version: #{version_gem})"
  run "passenger-install-nginx-module", %w(--auto --auto-download --prefix=/opt/nginx)  # install without prompting
  run "update-rc.d nginx defaults"                                                      # activate autostart
  run "service nginx restart"                                                           # restart nginx
end

Example - Sun JDK

The JDK can be installed as a package, of course, but the standard package requires you to agree to a license at install time. It would be nice to use debconf-set-selections to avoid the question and completely automate the install.

In your telfile:

apt "deb http://archive.canonical.com/ lucid partner"
recipes "jdk.rb"

recipes/jdk.rb

if !package_is_installed?("sun-java6-jre")
  File.open("/tmp/debconf_jdk", "w") { |f| f.write <<EOF }
sun-java6-jre shared/accepted-sun-dlj-v1-1 boolean true
EOF
  run "debconf-set-selections < /tmp/debconf_jdk"
  package_if_necessary("sun-java6-jre")
end
Something went wrong with that request. Please try again.