Add some Chef to your Capistrano

Moving towards automated server configuration with a small team

@leonid_shevtsov for @RubyGarage, 2012
Thursday, December 6, 12

About me
• • • •
Thursday, December 6, 12

I’m Leonid Shevtsov, http://l-s.me I code Ruby and Javascript at Railsware http://railsware.com I’ve configured and deployed tens of applications. (though no 100-server ones).

Why bother with CM tools?

You have to manage an infrastructure of hundreds of servers.

Thursday, December 6, 12

Why bother with CM tools?

You have to manage an infrastructure of hundreds of servers.

Thursday, December 6, 12

Don’t Use Manual Procedures
“The Pragmatic Programmer”,Tip 61

Thursday, December 6, 12

Why bother with CM tools?
• • •
Make implicit knowledge explicit; Turn configuration into code; Make configuration reusable.

Thursday, December 6, 12

What is server configuration?

• •

Imperatively: a list of commands executed by the sysop. Declaratively: a list of modifications of the files on the server.

Thursday, December 6, 12

Where is the server configuration?

• •

Best case scenario: in a log file/readme maintained by the sysop. Worst case scenario: just in the file modifications.

Thursday, December 6, 12

Make implicit knowledge explicit
• • • •
Thursday, December 6, 12

All configuration in one place; Indicate what options are customized/important; What if the sysadmin (or the “server guy”) gets sick (or fired)? Discourages (though doesn’t prohibit) cowboy debugging;

Turn configuration into code
• • • • • •
Thursday, December 6, 12

Programmers understand code. Code can be diffed Code can be merged You can collaborate on code You can share code between projects You can refactor code

Make configuration reusable
• • •
Scaling is a matter of refactoring; Really identical staging environment; Test entire stack on a virtual machine;

Thursday, December 6, 12

Automated server configuration is the future
(IMO)

Thursday, December 6, 12

But PaaS.

PaaS is OK if it’s OK for you, but...

• • •
Thursday, December 6, 12

do you have an identical staging environment? do you understand how it works? what the bottlenecks are? is it a leaky abstraction?

Chef

Thursday, December 6, 12

What is Chef?
• • •
A framework to build server configuration scripts powered by Ruby and JSON. No more powerful than shell script, but much more effective. Encapsulates common configuration patterns into resources.

Thursday, December 6, 12

user app_name do home "/home/#{app_name}" supports :manage_home => true end directory "/home/#{app_name}/apps/#{app_name}" do owner app_name group app_name mode 0700 recursive true end # nginx site record template "/etc/nginx/sites-available/#{app_name}" do source "nginx_site.erb" variables :app_name => app_name, :server_name => params[:server_name], :alternate_names => Array(params[:alternate_names]) end execute "ln -s /etc/nginx/sites-available/#{app_name} /etc/nginx/sites-enabled/#{app_name}" creates "/etc/nginx/sites-enabled/#{app_name}" notifies :reload, 'service[nginx]' end do

Thursday, December 6, 12

Push vs Pull

“Pull” configuration - suitable for major web sites

• • • • •
Thursday, December 6, 12

Servers update configuration automatically based on central node Requires infrastructure

“Push” configuration - suitable for “less than major” sites You update configuration manually on demand Natural next step from Capistrano

Cuoco
• • •
Capistrano can connect to and run commands on your server; Chef Solo can configure your server if it’s already there; Let’s use them together!

https://github.com/leonid-shevtsov/cuoco
Thursday, December 6, 12

How to add Chef to Capistrano
• • • • •
Thursday, December 6, 12

Capistrano should already have servers and roles Add Cuoco to your project Add a config/chef directory Start cooking! To run Chef, run cap
cuoco:run_roles

or just cap

deploy:setup

• • • •

To bootstrap & run Chef, run cap

cuoco:update_configuration

Works with capistrano multistage! Works with host & role filters! Servers pick up roles from Capistrano configuration

Thursday, December 6, 12

How do I start?

Thursday, December 6, 12

Requirements
• • •
Some experience with manual server configuration. Some experience with Ruby. A couple of days of free time.

Thursday, December 6, 12

Start small
• • • • •
Thursday, December 6, 12

https://github.com/leonid-shevtsov/cuoco_starter_kit Setup a virtual machine for development. Describe what you are already doing. DON’T overspecify & DON’T fix what is not broken. DON’T use a cookbook just because it exists.

Questions? Comments?
leonid@shevtsov.me Thanks to RailsWare http://railsware.com
Thursday, December 6, 12

Sign up to vote on this title
UsefulNot useful