Skip to content

Instantly share code, notes, and snippets.

@ringe
Last active August 29, 2015 14:10
Show Gist options
  • Save ringe/9797afc8e08865ce3bd9 to your computer and use it in GitHub Desktop.
Save ringe/9797afc8e08865ce3bd9 to your computer and use it in GitHub Desktop.
Prepare a Ubuntu 14.04 server for a rails app (with Norwegian support)
# config file for ansible -- http://ansible.github.com
# Set ANSIBLE_CONFIG environment variable to use this
# See http://ansible.github.com/examples.html#configuration-defaults
[defaults]
hostfile = ansible_hosts
remote_user = deploy
[servers]
192.168.0.13
deploy ALL=(ALL) NOPASSWD: ALL
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
server_name server.example.com;
passenger_enabled on;
passenger_spawn_method direct;
passenger_min_instances 2;
rails_app_spawner_idle_time 0;
rails_env production;
root /home/deploy/app/public;
# redirect server error pages to the static page /50x.html
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
---
- hosts: servers
sudo: true
vars:
rbenv:
env: user
version: v0.4.0
ruby_version: 2.1.5
roles:
- role: zzet.rbenv
rbenv_users:
- { name: "deploy", home: "/home/deploy", comment: "Deploy user" }
- role: abtris.nginx-passenger
- role: 'ssilab.locales'
locale: 'nb_NO'
encoding: 'UTF-8'
locales_user: 'deploy'
locale_language_packs:
- 'language-pack-nb'
- 'language-pack-nb-base'
tags:
- language
tasks:
- name: Set passwordless sudo for user deploy
copy: src=deploy dest=/etc/sudoers.d/deploy
tags: env
- name: Give www-data access to deploy group
user: name=www-data groups=deploy append=yes
- name: Install software
apt: pkg={{ item }} state=present
with_items:
- vim
- build-essential
- autoconf
- libssl-dev
- libyaml-dev
- libreadline6
- libreadline6-dev
- zlib1g
- zlib1g-dev
- mdbtools
- memcached
- redis-server
- sqlite3
- git-core
- curl
- zlib1g-dev
- build-essential
- libssl-dev
- libreadline-dev
- libyaml-dev
- libsqlite3-dev
- sqlite3
- libxml2-dev
- libxslt1-dev
- libcurl4-openssl-dev
- python-software-properties
- libsqlite3-dev
- freetds-common
- freetds-dev
- mongodb
- libreoffice
- smbclient
- wkhtmltopdf
- mariadb-client
- mariadb-common
- libmariadbclient-dev
- mariadb-server
- ruby-dev
- ack-grep
- name: Configure nginx sites
copy: src=nginx-default-site dest=/etc/nginx/sites-available/default owner=www-data group=www-data
notify: restart nginx
tags:
- web
- name: Enable nginx sites
file: src=/etc/nginx/sites-available/default dest=/etc/nginx/sites-enabled/default state=link
notify: restart nginx
tags:
- web
- name: Configure Sidekiq service
copy: src=sidekiq.conf dest=/etc/init/sidekiq.conf owner=root group=root mode="622"
tags: env
- name: set up gemrc
lineinfile: "dest='/home/deploy/.gemrc' state=present regexp='^gem' line='gem: --no-ri --no-rdoc'"
tags: env
- name: Install bundler gem
command: /home/deploy/.rbenv/versions/2.1.5/bin/gem install bundler
sudo: no
args:
chdir: /home/deploy
creates: /home/deploy/.rbenv/versions/2.1.5/bin/bundle
tags: env
- name: Set Rails environment
lineinfile: dest=/home/deploy/.bashrc state=present regexp="^export RAILS_ENV" line="export RAILS_ENV=production"
tags: env
- name: Set bx alias for bundle exec
lineinfile: dest=/home/deploy/.bashrc state=present regexp="alias bx" line="alias bx=\"bundle exec\""
tags: env
handlers:
- name: restart nginx
service: name=nginx state=restarted
- name: reconfigure locales
command: dpkg-reconfigure locales
# /etc/init/sidekiq.conf - Sidekiq config
description "Sidekiq Background Worker"
# no "start on", we don't want to automatically start
stop on (stopping workers or runlevel [06])
# change to match your deployment user
setuid deploy
setgid deploy
env HOME=/home/deploy
respawn
respawn limit 3 30
# TERM is sent by sidekiqctl when stopping sidekiq. Without declaring these as
# normal exit codes, it just respawns.
normal exit 0 TERM
script
# this script runs in /bin/sh by default
# respawn as bash so we can source in rbenv
exec /bin/bash <<'EOT'
source /home/deploy/.profile
source /etc/profile.d/rbenv.sh
cd /home/deploy/app
exec bundle exec sidekiq -c 3 -e production -L /home/deploy/gd/log/sidekiq.log
EOT
end script
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment