Download - Resources and providers chef conf 2013
![Page 1: Resources and providers chef conf 2013](https://reader033.vdocuments.us/reader033/viewer/2022060118/5589e641d8b42a980c8b45ef/html5/thumbnails/1.jpg)
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](https://reader033.vdocuments.us/reader033/viewer/2022060118/5589e641d8b42a980c8b45ef/html5/thumbnails/2.jpg)
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](https://reader033.vdocuments.us/reader033/viewer/2022060118/5589e641d8b42a980c8b45ef/html5/thumbnails/3.jpg)
1st Generation Cookbook Pattern
nginx/recipes/default.rb:
package 'nginx'service 'nginx'
![Page 4: Resources and providers chef conf 2013](https://reader033.vdocuments.us/reader033/viewer/2022060118/5589e641d8b42a980c8b45ef/html5/thumbnails/4.jpg)
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](https://reader033.vdocuments.us/reader033/viewer/2022060118/5589e641d8b42a980c8b45ef/html5/thumbnails/5.jpg)
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](https://reader033.vdocuments.us/reader033/viewer/2022060118/5589e641d8b42a980c8b45ef/html5/thumbnails/6.jpg)
![Page 7: Resources and providers chef conf 2013](https://reader033.vdocuments.us/reader033/viewer/2022060118/5589e641d8b42a980c8b45ef/html5/thumbnails/7.jpg)
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](https://reader033.vdocuments.us/reader033/viewer/2022060118/5589e641d8b42a980c8b45ef/html5/thumbnails/8.jpg)
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](https://reader033.vdocuments.us/reader033/viewer/2022060118/5589e641d8b42a980c8b45ef/html5/thumbnails/9.jpg)
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](https://reader033.vdocuments.us/reader033/viewer/2022060118/5589e641d8b42a980c8b45ef/html5/thumbnails/10.jpg)
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](https://reader033.vdocuments.us/reader033/viewer/2022060118/5589e641d8b42a980c8b45ef/html5/thumbnails/11.jpg)
A Provider can have many actions.
● :create● :delete● :enable● :disable● :modify● :deploy● :rollback● :run● :nothing
![Page 12: Resources and providers chef conf 2013](https://reader033.vdocuments.us/reader033/viewer/2022060118/5589e641d8b42a980c8b45ef/html5/thumbnails/12.jpg)
Providers can be overridden
nginx_instance 'example.com' do provider 'Chef::Provider::CorpNginx::Instance'end
![Page 13: Resources and providers chef conf 2013](https://reader033.vdocuments.us/reader033/viewer/2022060118/5589e641d8b42a980c8b45ef/html5/thumbnails/13.jpg)
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](https://reader033.vdocuments.us/reader033/viewer/2022060118/5589e641d8b42a980c8b45ef/html5/thumbnails/14.jpg)
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](https://reader033.vdocuments.us/reader033/viewer/2022060118/5589e641d8b42a980c8b45ef/html5/thumbnails/15.jpg)
Questions?