The most complex Chef recipe I have written is one that creates an entire web application stack from scratch. This recipe includes creating a web server, installing the necessary packages, configuring the server, and deploying the application code. The code for this recipe is as follows:

# Install web server package
package “nginx”

# Create web server configuration
template “/etc/nginx/sites-enabled/default” do
source “nginx.conf.erb”
end

# Install application packages
%w{python-pip python-dev libpq-dev}.each do |pkg|
package pkg do
action :install
end
end

# Install application dependencies
execute “pip install -r /var/www/app/requirements.txt”

# Deploy application code
deploy_revision “/var/www/app” do
repo “https://github.com/user/app.git”
user “www-data”
group “www-data”
migrate true
environment “RAILS_ENV” => “production”
action :deploy
end

# Restart web server
service “nginx” do
action :restart
end

Leave a Reply

Your email address will not be published. Required fields are marked *