Upgrade to Pro — share decks privately, control downloads, hide ads and more …

OpsWorks and Chef

OpsWorks and Chef

Joshua Timberman

April 19, 2013
Tweet

More Decks by Joshua Timberman

Other Decks in Technology

Transcript

  1. AWS OpsWorks Overview • Background • Initial Setup • Stacks,

    Layers, Instances, Apps • Lifecycle Events • Custom Chef Cookbooks 3 Thursday, April 18, 13
  2. Background • Peritor created Scalarium • EC2 UI + event

    based deployment • Built on Chef 0.9 • AWS acquired Peritor 4 Thursday, April 18, 13
  3. Initial Setup • Add OpsWorks to your AWS account. •

    There's no step 2! 5 Thursday, April 18, 13
  4. Step 2, Stacks, Layers, Apps • Add a stack •

    Add a layer • Add instances • Add your app • Profit! 6 Thursday, April 18, 13
  5. OpsWorks Agent • OpsWork agent runs on instances • It

    listens for lifecycle events • The lifecycle events trigger a Chef Solo run 10 Thursday, April 18, 13
  6. I left out some details... • AWS has OpsWorks guides

    • AWS has OpsWorks documentation • This talk doesn't cover those... 11 Thursday, April 18, 13
  7. Chef is a Framework • Configuration management • Reasonability •

    Idempotent, Convergent • Flexibility • Library & Primitives • TIMTOWTDI http://www.flickr.com/photos/elitatt/6980379333/ 14 Thursday, April 18, 13
  8. package "haproxy" do action :install end template "/etc/haproxy/haproxy.cfg" do source

    "haproxy.cfg.erb" owner "root" group "root" mode 0644 notifies :restart, "service[haproxy]" end service "haproxy" do supports :restart => true action [:enable, :start] end Chef Enables Infrastructure as Code • Resources • Recipes • Cookbooks and Roles • Source Code 15 Thursday, April 18, 13
  9. package “haproxy” {yum install haproxy apt-get install haproxy pacman sync

    haproxy pkg_add -r haproxy Chef Providers 19 Thursday, April 18, 13
  10. Chef comes in multiple flavors • Chef Solo • Chef

    Server • open source • Opscode Hosted Chef • Opscode Private Chef 21 Thursday, April 18, 13
  11. OpsWorks allows custom Chef Cookbooks • Set up custom Chef

    cookbooks on the Stack • Provide a URL to the cookbooks tar.gz • Add additional JSON data 23 Thursday, April 18, 13
  12. Create a Custom Layer • Create a new "custom" layer

    • Edit the layer 26 Thursday, April 18, 13
  13. Create an Instance • Go to the Instances page •

    Start the instance • OpsWorks will apply the Chef cookbooks. Automatically. 28 Thursday, April 18, 13
  14. Create an App • Create an app. • Call it

    "chef-runner" • This will trigger "deploy" lifecycle events • Have a recipe for deploying the app 29 Thursday, April 18, 13
  15. Inside opsworks_chef • OpsWorks Chef cookbook • Installs Chef 11

    alongside OpsWorks' Chef 0.9 • Sets up Chef Client w/ Chef Server • Runs chef-client daemonized 30 Thursday, April 18, 13
  16. remote_file package_local_path do source omnibus_package end package "chef" do source

    package_local_path provider Chef::Provider::Package::Rpm end opsworks_chef::setup (setup lifecycle event) 31 Thursday, April 18, 13
  17. opsworks_chef::configure (configure lifecycle event) directory "/etc/chef" file "/etc/chef/validation.pem" do content

    chef_config['validation_key'] end template "/etc/chef/client.rb" do variables(:chef_config => chef_config) end file "/etc/chef/opsworks.json" do content chef_config.to_json end 33 Thursday, April 18, 13
  18. opsworks_chef::client_service (included by configure recipe) file "/etc/sysconfig/chef-client" file "/etc/init.d/chef-client" directory

    "/var/log/chef" service "chef-client" do action [:enable, :start] end 34 Thursday, April 18, 13
  19. opsworks_chef::shutdown (shutdown lifecycle event) Chef::Config.from_file("/etc/chef/client.rb") chef_node_name = Chef::Config[:node_name] ruby_block "Remove

    #{chef_node_name} from Chef Server" do block do Chef::Node.load(chef_node_name).destroy Chef::ApiClient.load(chef_node_name).destroy end end file "/etc/chef/client.pem" do action :delete end 36 Thursday, April 18, 13
  20. Be aware • OpsWorks uses Chef 0.9 • OpsWorks includes

    ~20 cookbooks • Chef community site has over 800 cookbooks • Newer versions of Chef have incompatible features (platform family, attribute setting) 37 Thursday, April 18, 13
  21. OpsWorks is totally usable • OpsWorks is still an early

    phase product • More features, guides, training coming soon 38 Thursday, April 18, 13