1

I'm trying to figure out the correct way to architect a solution to automatically configure new Rails App servers.

I've looked at the chef-rails cookbook and it seems a little verbose. In our case we always deploy Nginx a certain way, always perform backups a certain way, etc, so much of the configuration would be redundant from one node definition to the next.

My goal is to be able to create a new Rails App server by defining just the following information.

wh_webhead "test_app" do
  ssl :enable
  backups :enable
  passenger :enable
  ruby_version 2.0.0
  db_type :mysql
  db_user "testuser"
  db_pass "3207496r9w6"
  nagios_ssl_string_match "login"
end

Then I would like Chef to perform the following actions:

  • Create user accounts
  • Setup box and install
  • Install Nginx w/wildcard SSL cert
  • Configure log rotation
  • Setup firewall rules to allow traffic to ports 80 and 443
  • Install Passenger and RVM with Ruby 2.0.0
  • Create Rails app dirs following template (e.g. /opt/local/test_app)
  • Create new database on MySQL server, grant access, and setup firewall rules
  • Create firewall rules for Nagios and configure Nagios to monitor:
    • port 80 for redirection to port 443
    • port 443 for HTTP 200 status
    • port 443 for the text "login"
  • Configure backups for app dir (e.g. /opt/local/test_app)

I'm already using the community cookbooks for Nginx, Nagios, Ufw, etc and have created recipes in a custom cookbook to configure Mysql and Nginx. There's just a lot of duplicate code from one app's Nginx/Mysql cookbook to the next.

What I'm struggling with is where to use Cookbooks, Recipes, LWRPs and Definitions to properly abstract this.

Should I put the default configuration for Nginx and Mysql in Definitions and then use those in recipes or create custom wrapper cookbooks with the defaults?

Andrew Hopper
  • 956
  • 2
  • 9
  • 20
  • 1
    possible duplicate of [chef libraries or definitions?](http://stackoverflow.com/questions/21725768/chef-libraries-or-definitions) – sethvargo Apr 19 '14 at 23:08
  • Thanks @sethvargo. Your explanation on [chef libraries or definitions?](http://stackoverflow.com/questions/21725768/chef-libraries-or-definitions) and JeanMetz comments below gave me exactly what I need. – Andrew Hopper Apr 23 '14 at 16:19

1 Answers1

2

First, take a look at the application_ruby and artifact cookbook, both of which can automate these workflows for you.

I specifically enjoy using the artifact cookbook, as it provides a lot of flexibility, but the application_ruby cookbook has built-in support for Passenger, Unicorn and other tools you'd normally find in a Rails application requirements.

As for your question regarding Cookbooks, Recipes, LWRPs and Definitions I would definitely look at @sethvargo's answer at https://stackoverflow.com/a/21733093/747032. It provides a good guide on what to use when, from an employee at Opscode (now called Chef (the company)), and someone who is constantly involved in the Chef community and thus has excellent knowledge on this topic.

As far as my advice (which I'll keep concise):

  • Use LWRP's to wrap a lot of resources that are always called together, for example, we use an "AWS EBS" LWRP, to create, mount and format new EBS'.
  • Use recipes to call on all your LWRP's (both custom and public) and resources.
  • Don't use definitions, they are really deprecated by LWRP's in my opinion.
Community
  • 1
  • 1
JeanMertz
  • 2,250
  • 2
  • 21
  • 26