Automated configuration management for small teams; Chef, Capistrano, Cuoco

Embed Size (px)

Citation preview

  • 7/30/2019 Automated configuration management for small teams; Chef, Capistrano, Cuoco

    1/24

    Add some Chef to yourCapistrano

    Moving towards automated server configuration with a small team

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

  • 7/30/2019 Automated configuration management for small teams; Chef, Capistrano, Cuoco

    2/24

    About me

    Im Leonid Shevtsov, http://l-s.me

    I code Ruby and Javascript at Railsware http://railsware.com

    Ive configured and deployed tens of applications.

    (though no 100-server ones).

    Thursday, December 6, 12

    http://railsware.com/http://railsware.com/http://l-s.me/http://l-s.me/
  • 7/30/2019 Automated configuration management for small teams; Chef, Capistrano, Cuoco

    3/24

    Why bother with CM tools

    You have to manage an infrastructure of hundreds of servers.

    Thursday, December 6, 12

  • 7/30/2019 Automated configuration management for small teams; Chef, Capistrano, Cuoco

    4/24

    Why bother with CM tools

    You have to manage an infrastructure of hundreds of servers.

    Thursday, December 6, 12

  • 7/30/2019 Automated configuration management for small teams; Chef, Capistrano, Cuoco

    5/24

    Dont Use Manual ProcedureThe Pragmatic Programmer

    Thursday, December 6, 12

  • 7/30/2019 Automated configuration management for small teams; Chef, Capistrano, Cuoco

    6/24

    Why bother with CM tools

    Make implicit knowledge explicit;

    Turn configuration into code;

    Make configuration reusable.

    Thursday, December 6, 12

  • 7/30/2019 Automated configuration management for small teams; Chef, Capistrano, Cuoco

    7/24

    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

  • 7/30/2019 Automated configuration management for small teams; Chef, Capistrano, Cuoco

    8/24

    Where is the server configurati

    Best case scenario: in a log file/readme maintained by the syso

    Worst case scenario: just in the file modifications.

    Thursday, December 6, 12

  • 7/30/2019 Automated configuration management for small teams; Chef, Capistrano, Cuoco

    9/24

    Make implicit knowledge expli

    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 doesnt prohibit) cowboy debugging;

    Thursday, December 6, 12

  • 7/30/2019 Automated configuration management for small teams; Chef, Capistrano, Cuoco

    10/24

    Turn configuration into code

    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

    Thursday, December 6, 12

  • 7/30/2019 Automated configuration management for small teams; Chef, Capistrano, Cuoco

    11/24

    Make configuration reusable

    Scaling is a matter of refactoring;

    Reallyidentical staging environment;

    Test entire stack on a virtual machine;

    Thursday, December 6, 12

  • 7/30/2019 Automated configuration management for small teams; Chef, Capistrano, Cuoco

    12/24

    Automated server configuratiothe future

    Thursday, December 6, 12

  • 7/30/2019 Automated configuration management for small teams; Chef, Capistrano, Cuoco

    13/24

  • 7/30/2019 Automated configuration management for small teams; Chef, Capistrano, Cuoco

    14/24

    Chef

    Thursday, December 6, 12

  • 7/30/2019 Automated configuration management for small teams; Chef, Capistrano, Cuoco

    15/24

    What is Chef?

    A framework to build server configuration scripts powered byand JSON.

    No more powerfulthan shell script, but much more effective.

    Encapsulates common configuration patterns into resources.

    Thursday, December 6, 12

  • 7/30/2019 Automated configuration management for small teams; Chef, Capistrano, Cuoco

    16/24

    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

    Thursday, December 6, 12

  • 7/30/2019 Automated configuration management for small teams; Chef, Capistrano, Cuoco

    17/24

    Push vs Pull

    Pull configuration - suitable for major web sites

    Servers update configuration automatically based on central

    Requires infrastructure

    Push configuration - suitable for less than major sites

    You update configuration manually on demand

    Natural next step from Capistrano

    Thursday, December 6, 12

  • 7/30/2019 Automated configuration management for small teams; Chef, Capistrano, Cuoco

    18/24

    Cuoco

    Capistrano can connect to and run commands on your server

    Chef Solo can configure your server if its already there;

    Lets use them together!

    https://github.com/leonid-she

    Thursday, December 6, 12

    https://github.com/leonid-shevtsov/cuocohttps://github.com/leonid-shevtsov/cuoco
  • 7/30/2019 Automated configuration management for small teams; Chef, Capistrano, Cuoco

    19/24

    How to add Chef to Capistra

    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

    Thursday, December 6, 12

  • 7/30/2019 Automated configuration management for small teams; Chef, Capistrano, Cuoco

    20/24

    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

  • 7/30/2019 Automated configuration management for small teams; Chef, Capistrano, Cuoco

    21/24

    How do I start?

    Thursday, December 6, 12

  • 7/30/2019 Automated configuration management for small teams; Chef, Capistrano, Cuoco

    22/24

    Requirements

    Some experience with manual server configuration.

    Some experience with Ruby.

    A couple of days of free time.

    Thursday, December 6, 12

  • 7/30/2019 Automated configuration management for small teams; Chef, Capistrano, Cuoco

    23/24

    https://github.com/leonid-shevtsov/cuoco_starter_kit

    Setup a virtual machine for development.

    Describe what you are already doing.

    DONT overspecify & DONT fix what is not broken.

    DONT use a cookbook just because it exists.

    Start small

    Thursday, December 6, 12

    https://github.com/leonid-shevtsov/cuoco_starter_kithttps://github.com/leonid-shevtsov/cuoco_starter_kit
  • 7/30/2019 Automated configuration management for small teams; Chef, Capistrano, Cuoco

    24/24

    Questions? Comments?

    [email protected] to RailsWare http://railsware.com

    Thursday, December 6, 12

    mailto:[email protected]:[email protected]:[email protected]:[email protected]:[email protected]