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?