15
Managing Resources and their Providers Resources and their Providers by Miah Johnson is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License .

Resources and providers chef conf 2013

Embed Size (px)

Citation preview

Page 1: Resources and providers chef conf 2013

Managing Resources and their Providers

Resources and their Providers by Miah Johnson is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.

Page 2: Resources and providers chef conf 2013

Hi, I'm [email protected]@miah_

Operations Engineer @ HotelTonight

I <3 automation, learning to solve all the problems, and look forward to the singularity.

Page 3: Resources and providers chef conf 2013

1st Generation Cookbook Pattern

nginx/recipes/default.rb:

package 'nginx'service 'nginx'

Page 4: Resources and providers chef conf 2013

nginx/recipes/default.rb:

include_recipe 'nginx::ohai_plugin' case node['nginx']['install_method']when 'source' include_recipe 'nginx::source'when 'package' case node['platform'] when 'redhat','centos','scientific','amazon','oracle' if node['nginx']['repo_source'] == 'epel' include_recipe 'yum::epel' else include_recipe 'nginx::repo' end end package node['nginx']['package_name'] service 'nginx' do supports :status => true, :restart => true, :reload => true action :enable end include_recipe 'nginx::commons'end

Page 5: Resources and providers chef conf 2013

This isn't flexible.

● What if I want more than one nginx instance?

● What if I want to change something?● Code layout can make debugging difficult.● Often have embedded search.● Many code paths to test.● Over 9000 attributes.● Limited to existing resources.

Page 6: Resources and providers chef conf 2013
Page 7: Resources and providers chef conf 2013

2nd Generation Composable Pattern

The 'composable' recipe

nginx/recipes/default.rb:

include_recipe 'nginx::_group'include_recipe 'nginx::_user.rb'include_recipe 'nginx::_server_install_from_source.rb'include_recipe 'nginx::_server_config'include_recipe 'nginx::_server_runit.rb'

Page 8: Resources and providers chef conf 2013

More flexible but.. ?

● Still limited to single instance● Have to wrap or fork to include local

customizations.corp_nginx/recipes/default.rb:

include_recipe 'nginx::_group'include_recipe 'nginx::_user.rb'include_recipe 'nginx::_server_config'include_recipe 'nginx::_server_install_from_source.rb'include_recipe 'corp_nginx::_server_bluepill.rb'

Page 9: Resources and providers chef conf 2013

3rd Generation Library Pattern

nginx_instance 'example.com' do path '/opt/example.com' user 'example' port 8080 server_alias 'www.example.com' action [:create, :enable]end

Page 10: Resources and providers chef conf 2013

Most flexible.

● Resources have unique names (yay instances).

● Resource attributes can have default values (less node attributes).

● Stable Public Interface.

Page 11: Resources and providers chef conf 2013

A Provider can have many actions.

● :create● :delete● :enable● :disable● :modify● :deploy● :rollback● :run● :nothing

Page 12: Resources and providers chef conf 2013

Providers can be overridden

nginx_instance 'example.com' do provider 'Chef::Provider::CorpNginx::Instance'end

Page 13: Resources and providers chef conf 2013

Wrap it up!

nginx/recipes/default.rb:

sites = data_bag('sites')

sites.each do |instance| nginx_instance instance['name'] do port instance['port'] endend

Page 14: Resources and providers chef conf 2013

Thanks!

● Mathieu Sauve-Frankel @kisoku● Ashe Dryden @ashedryden● Julie Pagano @juliepagano● Julia Elman @juliaelman● Lindsey Bieda @lindseybieda

Page 15: Resources and providers chef conf 2013

Questions?