Applying the sample template to a VPS - Reliably Deploying Rails Applications: Hassle free provisioning, reliable deployment (2014)

Reliably Deploying Rails Applications: Hassle free provisioning, reliable deployment (2014)

7.4 - Applying the sample template to a VPS

Overview

We now have the bare bones of a server configuration consisting of:

· Look and feel

· Localisation

· User structure

· Basic Firewall

· Locked down SSH

In our sample template, these minimal requirements for a server are contained in the server role found in roles/server.json.

Therefore a simple node definition for just applying these basic elements would look like this:

1 {

2 "environment":"production",

3 "run_list":

4 [

5 "role[server]"

6 ]

7 }

In this section we’ll apply this minimal node definition to a VPS and then continue to build on it in further chapters.

Pre-requisites

This chapter assumes you’ve followed along from the beginning of section 6, in particular that you have:

· cloned the example repository (https://github.com/TalkingQuickly/rails-server-template)

· Run berks install --path cookbooks to install the cookbooks locally

Step by step

The process is exactly the same one we followed for applying the simple redis configuration in 5.4

1) Copy your public key to your VPS:

1 ssh-copy-id root@yourserverip

2) Install chef on the remote machine

1 knife solo prepare root@yourserverip

3) Populate your new node definition nodes/yourserverip.json with the simple node definition:

1 {

2 "environment":"production",

3 "run_list":

4 [

5 "role[server]"

6 ]

7 }

4) Make sure you’ve set up your user data bags as per 7.1

5) Apply the node definition to the VPS

1 knife solo cook root@yourserverip

Hopefully the above really shows how simple Chef makes provisioning a new server. Once you’ve assembled a collection of roles and cookbooks you’re comfortable with, provisioning a new server is just four simple steps.

In fact if you have a node definition you’re regularly re-using you can save it as something like nodes/side_project_server.json and then use:

1 knife solo bootstrap root@yourserverip nodes/side_project_server.json

This will install chef on the VPS at yourserverip and apply the node definition nodes/yourserverip to it.

Showing that its worked

You should now be able to ssh into the server as the deploy user, authenticating with the public key you provided, for example:

1 ssh deploy@yourserverip

Once authenticated you can test that packages such as htop are available (just type htop for an easy on the eyes view of system resource usage). You can also use sudo ufw status to verify that the firewall is enabled and the rules we configured have been applied.