Slide 1

Slide 1 text

AWS OpsWorks and Opscode Chef Joshua Timberman @jtimberman 1 Thursday, April 18, 13

Slide 2

Slide 2 text

2 Thursday, April 18, 13

Slide 3

Slide 3 text

AWS OpsWorks Overview • Background • Initial Setup • Stacks, Layers, Instances, Apps • Lifecycle Events • Custom Chef Cookbooks 3 Thursday, April 18, 13

Slide 4

Slide 4 text

Background • Peritor created Scalarium • EC2 UI + event based deployment • Built on Chef 0.9 • AWS acquired Peritor 4 Thursday, April 18, 13

Slide 5

Slide 5 text

Initial Setup • Add OpsWorks to your AWS account. • There's no step 2! 5 Thursday, April 18, 13

Slide 6

Slide 6 text

Step 2, Stacks, Layers, Apps • Add a stack • Add a layer • Add instances • Add your app • Profit! 6 Thursday, April 18, 13

Slide 7

Slide 7 text

Lifecycle Events • Setup • Configure • Deploy • Undeploy • Shutdown 7 Thursday, April 18, 13

Slide 8

Slide 8 text

Each lifecycle event has corresponding Chef recipes 8 Thursday, April 18, 13

Slide 9

Slide 9 text

9 Thursday, April 18, 13

Slide 10

Slide 10 text

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

Slide 11

Slide 11 text

I left out some details... • AWS has OpsWorks guides • AWS has OpsWorks documentation • This talk doesn't cover those... 11 Thursday, April 18, 13

Slide 12

Slide 12 text

12 Thursday, April 18, 13

Slide 13

Slide 13 text

What is Chef? http://i3.kym-cdn.com/photos/images/original/000/046/123/magnets.jpg 13 Thursday, April 18, 13

Slide 14

Slide 14 text

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

Slide 15

Slide 15 text

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

Slide 16

Slide 16 text

Resources take action through Providers 16 Thursday, April 18, 13

Slide 17

Slide 17 text

Declarative interface to system resources 17 Thursday, April 18, 13

Slide 18

Slide 18 text

Describe what Not how. 18 Thursday, April 18, 13

Slide 19

Slide 19 text

package “haproxy” {yum install haproxy apt-get install haproxy pacman sync haproxy pkg_add -r haproxy Chef Providers 19 Thursday, April 18, 13

Slide 20

Slide 20 text

Providers perform the how 20 Thursday, April 18, 13

Slide 21

Slide 21 text

Chef comes in multiple flavors • Chef Solo • Chef Server • open source • Opscode Hosted Chef • Opscode Private Chef 21 Thursday, April 18, 13

Slide 22

Slide 22 text

Remember me? 22 Thursday, April 18, 13

Slide 23

Slide 23 text

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

Slide 24

Slide 24 text

URL to custom cookbooks.tar.gz 24 Thursday, April 18, 13

Slide 25

Slide 25 text

knife ec2 instance data -Fj 25 Thursday, April 18, 13

Slide 26

Slide 26 text

Create a Custom Layer • Create a new "custom" layer • Edit the layer 26 Thursday, April 18, 13

Slide 27

Slide 27 text

27 Thursday, April 18, 13

Slide 28

Slide 28 text

Create an Instance • Go to the Instances page • Start the instance • OpsWorks will apply the Chef cookbooks. Automatically. 28 Thursday, April 18, 13

Slide 29

Slide 29 text

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

Slide 30

Slide 30 text

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

Slide 31

Slide 31 text

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

Slide 32

Slide 32 text

opsworks_chef::configure (configure lifecycle event) # helper: chef_config = get_chef_config # runs: opsworks-agent-cli get_json 32 Thursday, April 18, 13

Slide 33

Slide 33 text

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

Slide 34

Slide 34 text

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

Slide 35

Slide 35 text

opsworks_chef::deploy (deploy lifecycle event, from app) execute "/etc/init.d/chef-client run" 35 Thursday, April 18, 13

Slide 36

Slide 36 text

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

Slide 37

Slide 37 text

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

Slide 38

Slide 38 text

OpsWorks is totally usable • OpsWorks is still an early phase product • More features, guides, training coming soon 38 Thursday, April 18, 13