Top Banner
Chef Infrastructure Automation for the Masses.™ http://www.opscode.com/chef/
24

Chef - Infrastructure Automation for the Masses

Aug 16, 2015

Download

Technology

Sai Perchard
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Chef - Infrastructure Automation for the Masses

Chef

Infrastructure Automation for the Masses.™

http://www.opscode.com/chef/

Page 2: Chef - Infrastructure Automation for the Masses

What is Chef?

• Open source systems integration framework

• Manage infrastructure via source code

• More complex infrastructure with less effort

• Best practices & collaboration via ‘recipes’

• Scalability

“Chef is an open source systems integration framework, built to bring the benefits of server configuration management to your entire infrastructure.”

Page 3: Chef - Infrastructure Automation for the Masses

Quick stats

• Released by Opscode January 15th, 2009

• Over 100 contributors as at March 1, 2010

– Engine Yard, Heroku, Rackspace, 37Signals

• Talent from Amazon, Microsoft, IBM, UBS.

Page 4: Chef - Infrastructure Automation for the Masses

How does it work?

• Infrastructure described via ‘Recipes’

– Describe a series of resources– Describe configuration of these resources

• Two flavours: Solo and Server

– Adam has discussed Solo, I will focus on Server

Page 5: Chef - Infrastructure Automation for the Masses

Chef Server

• A Merb app with indexing

• The Opscode Platform is a commercial cloud-based chef-server

– Free for up to 5 nodes

• You might use Chef Server if you want to…

– Search across the attributes of multiple nodes– Set up clustered services

• Data bags• Search• Centralisation

Page 6: Chef - Infrastructure Automation for the Masses

Terminology

• Nodes

– The things (e.g. server) configured by recipes.

• Roles

– A collection of recipes (or other roles).

• Cookbooks

– Recipes specify resources to manage

– Attributes are variables that can be mixed in to recipes

– Libraries extend Chef or provider helpers

– Files– Templates – Metadata tells Chef about your

recipes (inc. dependencies, platforms, etc.)

• Resources

– Things to be configured (e.g. a package or service)

• Providers

– Abstractions of system commands/API calls used to configure resources.

• Search

– Data stored on Chef server is indexed for search.

• Data bags

– Arbitrary stores of globally available JSON data

Page 7: Chef - Infrastructure Automation for the Masses

Differences from Chef Solo

• chef-client

• Knife

• Data bags

• Search

Page 8: Chef - Infrastructure Automation for the Masses

Search

Page 9: Chef - Infrastructure Automation for the Masses

chef-client

• An agent run by managed nodes

• Compiles and executes Cookbooks

• Can be daemonized to run periodically

$ chef-client -i 3600 -s 600 -d

Page 10: Chef - Infrastructure Automation for the Masses

Knife• The command line tool used to interact with Chef

server

• RESTful sub-commands: create, list & show, edit, delete

• Allows you to:

– Bootstrap a node (install Chef on a target system so it can run chef-client)

– List all nodes, or inspect a particular node, associated with an organisation

– Create new cloud instances – Manage cookbooks, data bags, nodes & roles– Search

Page 11: Chef - Infrastructure Automation for the Masses

Data Bags

• Only available to Chef Server

• Arbitrary stores of globally available JSON data

• Not directly associated with Node/Role attributes

• A central data store via which a cluster of infrastructure may be manipulated

• Managed using knife

Page 12: Chef - Infrastructure Automation for the Masses

1. Sign up for Opscode Platform

• Download user key

• Create an organisation

• Download validation key

• Download knife config file

• Sign up for the Opscode Platform at http://www.opscode.com/platform/• 5 nodes free• Chef Server is a Merb web application

Page 13: Chef - Infrastructure Automation for the Masses

2. Install Chef

$ sudo gem install chef

$ chef-client –v

Chef: 0.9.14

• Requirements

– Xcode– Rubygems 1.3.5+– Git

Page 14: Chef - Infrastructure Automation for the Masses

3. Create Chef repository

$ cd ~

$ git clone http://github.com/opscode/chef-repo.git

$ cd chef-repo/

$ ls

.git/

.gitignore

README.md

Rakefile

certificates/

cookbooks/

data_bags/

environments/

roles/

Page 15: Chef - Infrastructure Automation for the Masses

4. Create the .chef directory

• Contains configuration & authentication files

$ mkdir -p ~/chef-repo/.chef

$ cp ~/Downloads/*.pem .chef

$ cp ~/Downloads/*.rb .chef

$ ls .chef/

knife.rb

nexusnotes-validator.pem

sai.pem

Page 16: Chef - Infrastructure Automation for the Masses

5. Test your configuration

$ cd ~/chef-repo/

$ knife client list

[

"nexusnotes-validator"

]

Page 17: Chef - Infrastructure Automation for the Masses

6. Code your Infrastructure

$ knife cookbook site vendor apache2

$ knife cookbook upload apache2

$ knife cookbook list

Download the apache2 cookbook

Upload the apache2 cookbook to the Chef Server

List all of the cookbooks

• Find recipes at:

– http://community.opscode.com/cookbooks

Page 18: Chef - Infrastructure Automation for the Masses
Page 19: Chef - Infrastructure Automation for the Masses

7. Set up a Chef Client

• Use knife to bootstrap the target system

– Must set up OS & authentication first though

$ cd ~/chef-repo/

$ knife bootstrap HOSTNAME --distro DISTRO [centos5-gems]

Page 20: Chef - Infrastructure Automation for the Masses

8. Deploy your Infrastructure

• So far, we have:

– Signed up for the Opscode Platform (Chef Server)– Set up Chef locally– Vendored a cookbook and uploaded it to Chef Server– Bootstrapped a node

• Now we are ready to deploy

Page 21: Chef - Infrastructure Automation for the Masses

8. Deploy your Infrastructure

• Add the recipe to the node’s run list

• Run chef-client on the node as root

$ knife node run_list add HOSTNAME 'recipe[apache2]'

$ sudo chef client

...

Page 22: Chef - Infrastructure Automation for the Masses

8. Deploy your Infrastructure

• Example output

INFO: Starting Chef Run

INFO: Storing updated cookbooks/getting-started/recipes/default.rb in the cache.

INFO: Storing updated cookbooks/getting-started/README.rdoc in the cache.

INFO: Storing updated cookbooks/getting-started/metadata.rb in the cache.

INFO: Storing updated cookbooks/getting-started/metadata.json in the cache.

INFO: Storing updated cookbooks/getting-started/templates/default/chef-getting-started.txt.erb in the cache.

INFO: Writing updated content for template[/tmp/chef-getting-started.txt] to /tmp/chef-getting-started.txt

INFO: Chef Run complete in 8.950384 seconds

INFO: Running report handlers

INFO: Report handlers complete

Page 23: Chef - Infrastructure Automation for the Masses

Launching Cloud Instances

• Install dependencies

$ sudo gem install net-ssh net-ssh-multi fog highline

• Set up Knife with your AWS credentials

# ~/chef-repo/.chef/knife.rb

knife[:aws_access_key_id] = "Your AWS Access Key"

knife[:aws_secret_access_key] = "AWS Secret Access Key”

knife[:aws_ssh_key_id] = "knife"

Page 24: Chef - Infrastructure Automation for the Masses

Launch Instance

• Launch a new instance

$ knife ec2 server create 'recipe[apache2]'

-i ami-0c423c5e

-f t1.micro

-S knife

-I ~/.ssh/knife.pem

--ssh-user ubuntu

--region ap-southeast-1