Top Banner
Infrastructure Automation with Chef Jonathan Weiss 12.11.2010 1
51

Infrastructure Automation with Chef

May 10, 2015

Download

Self Improvement

Jonathan Weiss

Presented by Jonathan Weiss at Codebits.eu 2010 in Lissabon. Introduction into DevOps and Chef. How Chef works and how to use it.
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: Infrastructure Automation with Chef

Infrastructure Automation with Chef

Jonathan Weiss

12.11.2010

1

Page 2: Infrastructure Automation with Chef

Who am I?

Working for Peritor in Berlin, Germany

Written, maintain, or involved in

  Webistrano

  Capistrano

  SimplyStored

  Happening

  The great fire of London

http://github.com/jweiss

@jweiss

2

Page 3: Infrastructure Automation with Chef

Scalarium

Amazon EC2 Cluster Management

  Auto-Config

  Self-Healing

  Auto-Scaling

  One-click-deployment

www.scalarium.com

3

Page 4: Infrastructure Automation with Chef

4

DevOps Dev who? Ops what?

Page 5: Infrastructure Automation with Chef

Developers

5

It works on my machine…

We need Node.js ���in version x.y.z

BTW the deployment is due tomorrow

DEV

Page 6: Infrastructure Automation with Chef

SysAdmin We don’t

support that version

The architecture doesn’t match our network,

deployment, or security model

We weren’t consulted about ���

security / monitoring / backup / provisioning

OPS

Page 7: Infrastructure Automation with Chef

The blame game

OPS DEV

Page 8: Infrastructure Automation with Chef

WE SHOULD TALK!

OPS

WE SHOULD TALK!

DEV

Page 9: Infrastructure Automation with Chef

DevOps

Combined interest of developers and operations in

  Processes

  Communication

  Automation

Close cooperation based on common tools

9

Page 10: Infrastructure Automation with Chef

Automation

• Infrastructure

• Provisioning

• Deployment

flickr.com/photos/torek/3788181603

Page 11: Infrastructure Automation with Chef

Chef

Open Source Provisioning Tool

  Configures your servers

  Cookbooks & recipes

  Ruby DSL

11

Page 12: Infrastructure Automation with Chef

Chef Solo

12

Page 13: Infrastructure Automation with Chef

Chef

13

Page 14: Infrastructure Automation with Chef

14

Chef Single Server View Chef-Solo or Chef-Client

Page 15: Infrastructure Automation with Chef

Cookbooks

15

Cookbooks

apache2

memcached

mysql

rails

Page 16: Infrastructure Automation with Chef

Memcached Cookbook

16

Cookbooks

memcachd

attributes

recipes

templates

Page 17: Infrastructure Automation with Chef

Memcached Cookbook

17

memcached

attributes

default.rb

recipes

service.rb

install.rb

templates

default

memcached.conf.erb

Page 18: Infrastructure Automation with Chef

Attributes

18

cookbooks/memcached/attributes/default.rb

Set default values for variables to use in recipes & templates

Page 19: Infrastructure Automation with Chef

Recipes

19

cookbooks/memcached/recipes/service.rb

Actual instructions to execute

Page 20: Infrastructure Automation with Chef

Recipes

20

cookbooks/memcached/recipes/install.rb

Page 21: Infrastructure Automation with Chef

Templates

21

cookbooks/memcached/templates/default/memcached.conf.erb

Page 22: Infrastructure Automation with Chef

Chef Solo Run

22

Configuration JSON: /etc/chef/solo.json

Run Chef Solo

Page 23: Infrastructure Automation with Chef

Ohai

Detecs data about your local machine & OS   Kernel stats

  Modules & drivers

  Programming Languages

  Users

  Filesystems

  Network configuration

  ...

Populates attributes and makes them available for Chef

Extensible with plugins

23

Page 24: Infrastructure Automation with Chef

Ohai

24

$ ohai

Page 25: Infrastructure Automation with Chef

Ohai

25

recipes

attributes

Page 26: Infrastructure Automation with Chef

Resources

26

The steps that make up a recipe

Implemented by providers, depending on your platform (in this case apt-get, rpm, zypper or MacPorts)

Page 27: Infrastructure Automation with Chef

Available Resources

27

Cookbook File

Cron

Deploy

Directory

Erlang Call

Execute

File

Git

Group

HTTP Request

Ifconfig

Link

Log

Mdadm

Mount

Package

Remote Directory

Remote File

Route

Ruby Block

SCM

Script

Service

Subversion

Template

User

Page 28: Infrastructure Automation with Chef

User & Group Resource

28

Page 29: Infrastructure Automation with Chef

Cron Resource

29

Page 30: Infrastructure Automation with Chef

Execute Resource

30

Page 31: Infrastructure Automation with Chef

Package Resource

31

Page 32: Infrastructure Automation with Chef

Script Resource

32

Supports bash, csh, Ruby, Python, and Perl

Page 33: Infrastructure Automation with Chef

Deploying

Deploy resource   Compatible with Capistrano layout

  Supports Capistrano hooks via deploy/hook_name.rb

33

Page 34: Infrastructure Automation with Chef

Everything is Ruby

Very easy to extend

34

Page 35: Infrastructure Automation with Chef

Available in all Resources

Common methods:

  action

  provider

  Supports

  ignore_failure

  not_if / only_if

  notifies

  subscribes

35

Page 36: Infrastructure Automation with Chef

Notifications

Notifiy other resources to execute an action

Default notification happens at the end of the Chef run, optionally run it

36

Page 37: Infrastructure Automation with Chef

Roles

  Composites of recipes and attributes

 Nodes can have multiple roles

37

Page 38: Infrastructure Automation with Chef

Role Definition

38

$ cat roles/webserver.rb

Page 39: Infrastructure Automation with Chef

39

Chef Server Setup Multiple Chef-Clients talking to Chef-Server

Page 40: Infrastructure Automation with Chef

Architecture

40

Page 41: Infrastructure Automation with Chef

Web UI

Sinatra Web application to manage nodes, cookbooks & roles

41

Page 42: Infrastructure Automation with Chef

Knife

CLI tool for Chef-Server:   List nodes, cookbooks & attributes

  Assign roles

  Upload new cookbooks

42

Page 43: Infrastructure Automation with Chef

Solr

Search for nodes by attributes:

in recipes/templates

with knife

43

Page 44: Infrastructure Automation with Chef

44

Chef Annoyances Things that could be nicer

Page 45: Infrastructure Automation with Chef

Idempotent

Bug or feature?

45

Page 46: Infrastructure Automation with Chef

46

Will never happen, even if /data/logs/redhat will be created!

Page 47: Infrastructure Automation with Chef

Two Phases of Chef

1) Compile

Load all attributes&recipes and build list of actions/dependencies

Compute attribute tree

2) Run

Actually execute the resources

47

Random Ruby Code runs here

Page 48: Infrastructure Automation with Chef

Two Phases of Chef

 Use only_if and not_if

 Tell Chef to execute your ressource during compile phase

48

Page 49: Infrastructure Automation with Chef

Chef Experiences

Great way to automate provisioning of servers

  Infrastructure as code

  Understandable by dev & ops

  Easy to extend

  Easy to integrate in management framework (SSH, mcollective, Nanite, ..)

  Ignore Chef-Server when starting to play with Chef

49

Page 50: Infrastructure Automation with Chef

50

DEV OPS

Page 51: Infrastructure Automation with Chef

© Peritor GmbH - Alle Rechte vorbehalten

Peritor GmbH Blücherstr. 22, Hof III Aufgang 6 10961 Berlin

Tel.: +49 (0)30 69 20 09 84 0 Fax: +49 (0)30 69 20 09 84 9

Internet: www.peritor.com E-Mail: [email protected]