Slide 1

Slide 1 text

Cookbook Reusability! Chef Community Summit 2014

Slide 2

Slide 2 text

Sean OMeara! [email protected]! @someara

Slide 3

Slide 3 text

whoami

Slide 4

Slide 4 text

A Year in Review

Slide 5

Slide 5 text

Diversification

Slide 6

Slide 6 text

7zip! apache2! ark! application*! couchdb! Imagemagick! java

Slide 7

Slide 7 text

logrotate! mercurial! munin! nagios! nginx! ntp! openvpn

Slide 8

Slide 8 text

pacman! postgresql! python! reprepro! rabbitmq! runit! supervisor

Slide 9

Slide 9 text

selinux! tmux! varnish ! wordpress!

Slide 10

Slide 10 text

Supermarket https://www.flickr.com/photos/mobilestreetlife/10885044043

Slide 11

Slide 11 text

• Escaped the tyranny of JIRA! • Moved to Github Issues! • Automated CLA checking! • OSS Artifact Repository

Slide 12

Slide 12 text

Rewrites

Slide 13

Slide 13 text

2009 0.5.2 Chef Vagrant ChefSpec 0.1.0 0.0.2 Minitest-Chef Berkshelf Test Kitchen 2010 0.9.0 2011 0.10.0 2012 10.12.0 1.0.0 0.2.0 1.0.0 0.7.0 1.0.0 2013 2014 1.0.0 2.0.0 1.0.0 2.0.0 1.4.0 11.0.0 12.0.0 1.6.5 3.0.0 3.0.0 1.2.2 ServerSpec ChefDK 0.0.1 2.0.0 0.2.2 TDI Capability 0.8.0

Slide 14

Slide 14 text

yum! yum-*! jenkins! mysql! httpd

Slide 15

Slide 15 text

The Evolution of a Chef Cookbook

Slide 16

Slide 16 text

Stage 1 - Paradise https://www.flickr.com/photos/nattu/1385100375/

Slide 17

Slide 17 text

No content

Slide 18

Slide 18 text

test / repair test / repair test / repair

Slide 19

Slide 19 text

Easy to read Easy to grok Easy to test }

Slide 20

Slide 20 text

Stage 2 - if statements

Slide 21

Slide 21 text

logic compiled into resource collection

Slide 22

Slide 22 text

Resource DSL } Just Ruby }

Slide 23

Slide 23 text

Resource DSL } Just Ruby } }Chef

Slide 24

Slide 24 text

Stage 3 - Crazytown https://www.flickr.com/photos/kwl/4595324641

Slide 25

Slide 25 text

No content

Slide 26

Slide 26 text

wat

Slide 27

Slide 27 text

Why?

Slide 28

Slide 28 text

Reusable is useful

Slide 29

Slide 29 text

Cross-platform is useful

Slide 30

Slide 30 text

We desire useful things

Slide 31

Slide 31 text

Platform idioms are hard

Slide 32

Slide 32 text

Keeping the Dream Alive https://www.flickr.com/photos/kalexanderson/7014655351/

Slide 33

Slide 33 text

Most people just write their own cookbooks from scratch

Slide 34

Slide 34 text

I really really really want reusable cross-platform cookbooks

Slide 35

Slide 35 text

Lessons Learned

Slide 36

Slide 36 text

Attributes are routinely abused https://www.flickr.com/photos/jabberwocky381/2828863789

Slide 37

Slide 37 text

No content

Slide 38

Slide 38 text

Attributes are an interface

Slide 39

Slide 39 text

Attributes are tunable knobs

Slide 40

Slide 40 text

No content

Slide 41

Slide 41 text

You probably just want a variable

Slide 42

Slide 42 text

No content

Slide 43

Slide 43 text

Or even a method

Slide 44

Slide 44 text

No content

Slide 45

Slide 45 text

Using an attribute to track state during a Chef run causes tears and sorrow

Slide 46

Slide 46 text

Prefer resource parameters

Slide 47

Slide 47 text

No content

Slide 48

Slide 48 text

No content

Slide 49

Slide 49 text

Primitives are more useful than opinionated policy

Slide 50

Slide 50 text

“They’re Just Resources”! ! LWRP is Googleable

Slide 51

Slide 51 text

Zoom out a level! ! Think about services and runtimes, not files and processes

Slide 52

Slide 52 text

Singleton resources are good but confusing. Possibly even dangerous.! ! Multiple instance support is better! ! Cross-platform resources are best

Slide 53

Slide 53 text

No content

Slide 54

Slide 54 text

BDD / TDD yields high quality cookbooks https://www.flickr.com/photos/glenirah/4376553184

Slide 55

Slide 55 text

Test Kitchen! ServerSpec / Minitest / Bats! ChefSpec

Slide 56

Slide 56 text

2009 0.5.2 Chef Vagrant ChefSpec 0.1.0 0.0.2 Minitest-Chef Berkshelf Test Kitchen 2010 0.9.0 2011 0.10.0 2012 10.12.0 1.0.0 0.2.0 1.0.0 0.7.0 1.0.0 2013 2014 1.0.0 2.0.0 1.0.0 2.0.0 1.4.0 11.0.0 12.0.0 1.6.5 3.0.0 3.0.0 1.2.2 ServerSpec ChefDK 0.0.1 2.0.0 0.2.2 This Slide Again 0.8.0

Slide 57

Slide 57 text

Full test coverage is tedious

Slide 58

Slide 58 text

Full test coverage is totally worth it

Slide 59

Slide 59 text

Let users bring their own configurations

Slide 60

Slide 60 text

It is better to add to a resource_collection than to monkey patch it

Slide 61

Slide 61 text

Configuration files are the brains of a service

Slide 62

Slide 62 text

Manage minimal configuration to get a service running

Slide 63

Slide 63 text

Offload further configuration to the user

Slide 64

Slide 64 text

conf.d is your friend

Slide 65

Slide 65 text

Hide everything else inside a resource

Slide 66

Slide 66 text

Add resource parameters when appropriate

Slide 67

Slide 67 text

No content

Slide 68

Slide 68 text

No content

Slide 69

Slide 69 text

Cross-platform cookbooks are hard https://www.flickr.com/photos/glenirah/4376553184

Slide 70

Slide 70 text

Cross-platform resources are even harder

Slide 71

Slide 71 text

They can be done!

Slide 72

Slide 72 text

Create a resource

Slide 73

Slide 73 text

No content

Slide 74

Slide 74 text

Create a provider

Slide 75

Slide 75 text

No content

Slide 76

Slide 76 text

Subclass platform providers

Slide 77

Slide 77 text

No content

Slide 78

Slide 78 text

No content

Slide 79

Slide 79 text

No content

Slide 80

Slide 80 text

No content

Slide 81

Slide 81 text

No content

Slide 82

Slide 82 text

Set provider default for platforms

Slide 83

Slide 83 text

No content

Slide 84

Slide 84 text

Do Repeat Yourself

Slide 85

Slide 85 text

Some resources are often the duplicated across providers

Slide 86

Slide 86 text

That’s fine. It’s the pattern as a whole that’s important

Slide 87

Slide 87 text

Maximize for grokability

Slide 88

Slide 88 text

People will be reading your code for the first time during operations work

Slide 89

Slide 89 text

Init systems are annoying

Slide 90

Slide 90 text

Using a service resource usually requires file or template resources in addition to service[thingd]

Slide 91

Slide 91 text

Debconf! Docker! LaunchD! Runit! SMF! Simple! SystemD! Sysvinit! Upstart! Windows Services

Slide 92

Slide 92 text

Subclassing is awesome

Slide 93

Slide 93 text

No content

Slide 94

Slide 94 text

Customize before recipe compilation

Slide 95

Slide 95 text

Going Forward

Slide 96

Slide 96 text

Cookbooks that ship resource primitives

Slide 97

Slide 97 text

More examples to copy

Slide 98

Slide 98 text

More breaking backwards compatibility (sorry)

Slide 99

Slide 99 text

Providers implemented with Docker containers (why not?)

Slide 100

Slide 100 text

chef-metal

Slide 101

Slide 101 text

Tell me what you think

Slide 102

Slide 102 text

Please don’t hurt me =)

Slide 103

Slide 103 text

No content