Lock in $30 Savings on PRO—Offer Ends Soon! ⏳
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Cookbook Reusability
Search
someara
October 02, 2014
Technology
0
720
Cookbook Reusability
Chef Summit 2014
someara
October 02, 2014
Tweet
Share
More Decks by someara
See All by someara
Docker Docker Docker Chef
someara
0
480
Hand Crafted Artisinal Chef Resources
someara
0
580
Configuration Management Camp 2015
someara
1
550
TDI with ChefDK 0.0.1
someara
2
860
Configuration Management 101 @ Scale12x
someara
2
870
Configuration Management 101
someara
3
760
Introduction to Chef - Scale 10x
someara
2
440
Introduction to Chef - NYLUG Jan 2012
someara
2
290
Introduction to Chef - LISA11
someara
10
6.1k
Other Decks in Technology
See All in Technology
ChatGPTで論⽂は読めるのか
spatial_ai_network
0
370
寫了幾年 Code,然後呢?軟體工程師必須重新認識的 DevOps
cheng_wei_chen
1
1.1k
AIと二人三脚で育てた、個人開発アプリグロース術
zozotech
PRO
0
690
エンジニアリングマネージャー はじめての目標設定と評価
halkt
0
260
バグハンター視点によるサプライチェーンの脆弱性
scgajge12
3
1k
文字列の並び順 / Unicode Collation
tmtms
0
120
WordPress は終わったのか ~今のWordPress の制作手法ってなにがあんねん?~ / Is WordPress Over? How We Build with WordPress Today
tbshiki
1
430
Microsoft Agent 365 を 30 分でなんとなく理解する
skmkzyk
1
1k
EM歴1年10ヶ月のぼくがぶち当たった苦悩とこれからへ向けて
maaaato
0
270
今年のデータ・ML系アップデートと気になるアプデのご紹介
nayuts
1
190
re:Invent 2025 ふりかえり 生成AI版
takaakikakei
1
180
学習データって増やせばいいんですか?
ftakahashi
1
270
Featured
See All Featured
Building a Modern Day E-commerce SEO Strategy
aleyda
45
8.3k
A Tale of Four Properties
chriscoyier
162
23k
Large-scale JavaScript Application Architecture
addyosmani
515
110k
Code Review Best Practice
trishagee
74
19k
GitHub's CSS Performance
jonrohan
1032
470k
A better future with KSS
kneath
240
18k
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
3
390
We Have a Design System, Now What?
morganepeng
54
7.9k
The Power of CSS Pseudo Elements
geoffreycrofte
80
6.1k
For a Future-Friendly Web
brad_frost
180
10k
GraphQLの誤解/rethinking-graphql
sonatard
73
11k
The Cost Of JavaScript in 2023
addyosmani
55
9.3k
Transcript
Cookbook Reusability! Chef Community Summit 2014
Sean OMeara!
[email protected]
! @someara
whoami
A Year in Review
Diversification
7zip! apache2! ark! application*! couchdb! Imagemagick! java
logrotate! mercurial! munin! nagios! nginx! ntp! openvpn
pacman! postgresql! python! reprepro! rabbitmq! runit! supervisor
selinux! tmux! varnish ! wordpress!
Supermarket https://www.flickr.com/photos/mobilestreetlife/10885044043
• Escaped the tyranny of JIRA! • Moved to Github
Issues! • Automated CLA checking! • OSS Artifact Repository
Rewrites
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
yum! yum-*! jenkins! mysql! httpd
The Evolution of a Chef Cookbook
Stage 1 - Paradise https://www.flickr.com/photos/nattu/1385100375/
None
test / repair test / repair test / repair
Easy to read Easy to grok Easy to test }
Stage 2 - if statements
logic compiled into resource collection
Resource DSL } Just Ruby }
Resource DSL } Just Ruby } }Chef
Stage 3 - Crazytown https://www.flickr.com/photos/kwl/4595324641
None
wat
Why?
Reusable is useful
Cross-platform is useful
We desire useful things
Platform idioms are hard
Keeping the Dream Alive https://www.flickr.com/photos/kalexanderson/7014655351/
Most people just write their own cookbooks from scratch
I really really really want reusable cross-platform cookbooks
Lessons Learned
Attributes are routinely abused https://www.flickr.com/photos/jabberwocky381/2828863789
None
Attributes are an interface
Attributes are tunable knobs
None
You probably just want a variable
None
Or even a method
None
Using an attribute to track state during a Chef run
causes tears and sorrow
Prefer resource parameters
None
None
Primitives are more useful than opinionated policy
“They’re Just Resources”! ! LWRP is Googleable
Zoom out a level! ! Think about services and runtimes,
not files and processes
Singleton resources are good but confusing. Possibly even dangerous.! !
Multiple instance support is better! ! Cross-platform resources are best
None
BDD / TDD yields high quality cookbooks https://www.flickr.com/photos/glenirah/4376553184
Test Kitchen! ServerSpec / Minitest / Bats! ChefSpec
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
Full test coverage is tedious
Full test coverage is totally worth it
Let users bring their own configurations
It is better to add to a resource_collection than to
monkey patch it
Configuration files are the brains of a service
Manage minimal configuration to get a service running
Offload further configuration to the user
conf.d is your friend
Hide everything else inside a resource
Add resource parameters when appropriate
None
None
Cross-platform cookbooks are hard https://www.flickr.com/photos/glenirah/4376553184
Cross-platform resources are even harder
They can be done!
Create a resource
None
Create a provider
None
Subclass platform providers
None
None
None
None
None
Set provider default for platforms
None
Do Repeat Yourself
Some resources are often the duplicated across providers
That’s fine. It’s the pattern as a whole that’s important
Maximize for grokability
People will be reading your code for the first time
during operations work
Init systems are annoying
Using a service resource usually requires file or template resources
in addition to service[thingd]
Debconf! Docker! LaunchD! Runit! SMF! Simple! SystemD! Sysvinit! Upstart! Windows
Services
Subclassing is awesome
None
Customize before recipe compilation
Going Forward
Cookbooks that ship resource primitives
More examples to copy
More breaking backwards compatibility (sorry)
Providers implemented with Docker containers (why not?)
chef-metal
Tell me what you think
Please don’t hurt me =)
None