Beruflich Dokumente
Kultur Dokumente
ChefConf 2015
Kennon Kwok
Solutions Engineer - Chef Software, Inc.
mini-me
Mars
Zack Zondlo
Support Engineer
Previously: Senior Infrastructure Engineer, CareCloud
Previously: Senior Infrastructure Engineer, Selling Source
Kevin Dickerson
Solutions Engineer - Chef Software, Inc.
Kevin is a former sandwich artisan from Alaska.
He's previously worked at places like Carnegie Mellon University, Salesforce, and
Chef.
Interests include machine learning algorithms, super big web applications, and
software automation.
Sean Carolan
Solutions Architect - Chef Software, Inc.
Previously: Unix Systems Administrator at Electronic Arts
Worked with CFEngine, Puppet, and now Chef
Now: Sips martinis with the sales team
Introduce Yourselves
Name
Current job role
Previous job roles/background
Experience with Chef and/or config management
Favorite Text Editor
Agenda
Morning
Afternoon
Other logistics
Course style
Training is a discussion
Hands-on labs
Lots of typing
Ask questions when they come to you
Ask for help when you need it
We will troubleshoot issues on the spot
Chef Provisioning
An Introduction
Chef Provisioning
Allows programatic creation of cloud resources
in Chef Recipes
Allows for multiple tiers to be created in one
shot
Moves more towards Infrastructure as Code
Test and repair also applies to infrastructure
Previously known as chef-metal
Chef Provisioning
Plugin model lets you write bootstrappers for
https://github.com/chef/chef-provisioning-aws
Provisioning workflows
Chef Server with provisioning node
Chef Client local-mode
Provisioning workstation
EC2 instance, CentOS 6
Contains pre-installed software: ChefDK 0.4.0,
Chef Provisioning
WordPress walkthrough
Problem
Success
cluster
- Soup-to-nuts
- 3 tiers:
-
-
-
database (mysql)
application (php)
load balancer (ELB)
- github.com/kennonkwok/
wordpress-simple
REMOTE
-p, --policy-only
-g GENERATOR_COOKBOOK_PATH,
cookbook
--generator-
REMOTE
REMOTE
REMOTE
cookbooks
cookbooks directory is
in .gitignore
recipes only contain
provisioning code
recipes can contain
application tiers or driver
specific code
REMOTE
Create File
.chef/knife.rb
current_dir = File.dirname(__FILE__)
chef_repo_path "#{current_dir}/.."
Best Practice
De-couple provider specific code
Create file
recipes/_aws_settings.rb
require 'chef/provisioning/aws_driver'
with_driver 'aws'
with_machine_options(
bootstrap_options: {
instance_type: node['wordpress-cluster']['aws']['flavor'],
key_name: node['wordpress-cluster']['aws']['key_name'],
security_group_ids: node['wordpress-cluster']['aws']['security_group_ids']
},
ssh_username: node['wordpress-cluster']['aws']['ssh_username'],
image_id:
node['wordpress-cluster']['aws']['image_id']
)
aws_key_pair node['wordpress-cluster']['aws']['key_name']
REMOTE
Create file
attributes/default.rb
default['wordpress-cluster']['aws']['flavor'] = 't1.micro'
default['wordpress-cluster']['aws']['key_name'] = YOUR_KEY_NAME_HERE
default['wordpress-cluster']['aws']['security_group_ids'] = 'sg-c49e0ff4'
default['wordpress-cluster']['aws']['ssh_username'] = 'root'
default['wordpress-cluster']['aws']['image_id'] = 'ami-37361807'
open internally
use a unique key_name (e.g. kennon-wp-cluster)
Create file
recipes/database.rb
require 'chef/provisioning'
include_recipe 'wordpress-cluster::_aws_settings'
machine 'wordpress-database' do
tag 'wordpress-database'
recipe 'wordpress-simple::database
action :converge
end
The machine resource defines one (or more) machines and can
Best Practice
Create a destroy recipe
Create File
recipes/destroy_all.rb
include_recipe 'wordpress-cluster::_aws_settings'
machine_batch do
machines search(:node, '*:*').map { |n| n.name }
action :destroy
end
client data
Modify file
metadata.rb
name
'wordpress-cluster'
maintainer
'The Authors'
maintainer_email 'you@example.com'
license
'all_rights'
description
'Installs/Configures wordpress-cluster'
long_description 'Installs/Configures wordpress-cluster'
version
'0.1.0
depends 'wordpress-simple'
Berkshelf
Cookbook dependency manager
Included in ChefDK
Well use it here to download a WordPress
Modify file
Berksfile
source 'https://supermarket.chef.io'
metadata
cookbook 'wordpress-simple', git: 'https://github.com/kennonkwok/wordpress-simple.git'
Helpful one-liners
$ rm -fr cookbooks; berks vendor cookbooks
$ chef-client -z -o wordpress-cluster::destroy_all
REMOTE
Converge!
$ chef-client -z -o wordpress-cluster::database
...
seconds
- run 'chef-client -l auto' on wordpress-database
[2015-03-23T23:58:43+00:00] WARN: Skipping final node save because override_runlist was given
Running handlers:
Running handlers complete
Chef Client finished, 1/1 resources updated in 429.529162915 seconds
REMOTE
Converge!
$ rm -fr cookbooks; berks vendor cookbooks
$ chef-client z o wordpress-cluster::app
REMOTE
Converge!
$ rm -fr cookbooks; berks vendor cookbooks
$ chef-client z o wordpress-cluster::lb
REMOTE
#
# Cookbook Name:: wordpress-cluster
# Recipe:: default
#
# Copyright (c) 2015 The Authors, All Rights Reserved.
include_recipe 'wordpress-cluster::database'
include_recipe 'wordpress-cluster::app'
include_recipe 'wordpress-cluster::lb'
include_recipe 'wordpress-cluster::_aws_settings'
machine_batch do
machines search(:node, '*:*').map { |n| n.name }
action :destroy
end
load_balancer 'your-elb-name' do
action :destroy
end
TODO
Converge!
$ rm -fr cookbooks; berks vendor cookbooks
$ chef-client z o wordpress-cluster::app
REMOTE
Soup to nuts!
$ chef-client z o wordpress-cluster::default
- create data bag item wordpress-elb at http://localhost:8889
add location = {"driver_url"=>"aws", "driver_version"=>"0.4.0",
"allocated_at"=>"2015-03-24 03:34:09 UTC"}
[2015-03-24T03:34:09+00:00] WARN: Skipping final node save because override_runlist was given
Running handlers:
Running handlers complete
Chef Client finished, 3/3 resources updated in 629.509273264 seconds
REMOTE
Discussion
What questions can I answer for you?
Chef Provisioning
machine resource
Morning
Afternoon
Break