Deploying a Rails App to AWS Using Ansible

August 11, 2016
software development ansible devops automation

[Update 13 September 2016 - Merged playbooks into 1]

In the past week, I’ve been exploring how to automate the deployment of a Rails application into production on an AWS infrastructure. Ideally, I would like to have an environment consisting of 2 EC2 instances behind a load balancer and a Postgres database running on RDS. The Rails application requires Ruby 2.3.0 and uses PostgreSQL as a database.

This post assumes the Ansible host has been set up with AWS Access Key ID and AWS Secret Access Key as environment variables and there is an existing EC2 keypair.

The playbook deploy.yml does all the weight lifting from setting up AWS EC2 instances, PostgreSQL on AWS RDS, AWS ELB classic load balancer, installing ruby, rails and booting servers, up to registering EC2 instances to ELB.

Here is an overview of the roles, which can be found in the Gist below:

  1. setup_aws
  2. package_app
  3. install_ruby
  4. install_nginx
  5. webserver
  6. setup_elb

setup_aws does the following:

The other roles perform the following:

  1. Installs Ruby, Rails, Nginx, and other dependencies on EC2 instances using roles install_ruby, install_nginx,
  2. Precompiles and packages the Rails application locally using role package_app
  3. Copies Rails application to the EC2 instances and boot in production mode using role webserver
  4. Register both EC2 instances to ELB using role setup_elb

Stubbing Dependencies in Go

A quick guide to stubbing dependencies in Go
software development go test tdd

Map Reduce Illustrated

Understand map and reduce through visual illustrations
software development map reduce functional programming declarative programming

React on Rails with Webpack

A short guide to creating a React application in a Rails project. Uses webpack with Babel to transpile and bundle the application.
development software react rails webpack