Skip to content
Ansible: Ruby on Rails Server
Branch: master
Clone or download
Pull request Compare This branch is 4 commits ahead, 1 commit behind aleks:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

Ansible: Ruby on Rails Server

Use this ansible playbook to setup a fresh server with the following components:

  • Nginx
  • Puma App Server
  • Certbot (Let's Encrypt)
  • MySQL
  • Memcached
  • Redis
  • Sidekiq
  • Monit (to keep Puma and Sidekiq runnig)
  • Elasticsearch
  • ruby-install
  • chruby
  • Directories to deploy Rails with Capistrano and Puma App Server (see below)
  • Swapfile (useful for small DO instances)
  • Locales
  • Tools (tmux, vim, htop, git, wget, curl etc.)

Prerequisites & Config

  1. Rename hosts.example to hosts and modify the contents.

  2. Rename group_vars/all.example to group_vars/all and modify the contentes.

    There are a bunch of things you can set in group_vars/all. Don't forget to add your host address to hosts.

Install Playbook

Run ansible-playbook site.yml -i hosts.

Rails Setup

This is just a loose guideline for what you need to deploy your app with this playbook and server config. Please keep in mind, that you need to modify some values depending on your setup (especially passwords and paths!)


Add the following gems to your Gemfile and install via bundle install:

group :development do
  gem 'capistrano', '~> 3.6'
  gem 'capistrano-rails', '~> 1.2'
  gem 'capistrano-chruby'
  gem 'capistrano3-puma'
  gem 'capistrano-sidekiq'
  gem 'capistrano-npm'


Add the following lines to your Capfile:

# General
require 'capistrano/rails'
require 'capistrano/bundler'
require 'capistrano/rails/migrations'
require 'capistrano/rails/assets'
require 'capistrano/chruby'
require 'capistrano/npm'

# Puma
require 'capistrano/puma'
install_plugin Capistrano::Puma  # Default puma tasks
install_plugin Capistrano::Puma::Workers  # if you want to control the workers (in cluster mode)
# install_plugin Capistrano::Puma::Jungle # if you need the jungle tasks
install_plugin Capistrano::Puma::Monit  # if you need the monit tasks
install_plugin Capistrano::Puma::Nginx  # if you want to upload a nginx site template

# Sidekiq
require 'capistrano/sidekiq'
require 'capistrano/sidekiq/monit'


Please edit "deploy_app_name", "repo_url", "deploy_to" and "chruby_ruby" (if you've changed the Ruby version in group_vars/all).

Your config/deploy.rb should look similar to this example:

set :application, 'deploy_app_name'
set :repo_url, 'YOUR_GIT_REPO'
set :deploy_to, '/home/deploy/deploy_app_name'
set :chruby_ruby, 'ruby-2.3.3'
set :nginx_use_ssl, true
set :puma_init_active_record, true
set :linked_files, fetch(:linked_files, []).push('config/database.yml', 'config/secrets.yml')
set :linked_dirs, fetch(:linked_dirs, []).push('log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'public/system')
set :keep_releases, 5


Add the target host:

server 'your_host_address', user: 'deploy', roles: %w{app db web}


Feel free to send feedback or report problems via GitHub issues!


  • ansible-galaxy install zzet.rbenv 安装 rbenv playbook
  • ansible-galaxy install geerlingguy.nodejs 安装 nodejs playbook, 包含 yarn
  • Run ansible-playbook common.yml -i hosts.
  • Run ansible-playbook site.yml -i hosts.

使用 yarn playbook 之后, yanr 的目录 cap 找不到; 需要做个软链: sudo ln -s /usr/local/lib/npm/lib/node_modules/yarn/bin/yarn.js /usr/bin/yarn

You can’t perform that action at this time.