the place where the workflow tools are built • ChefDK isn't the only place where we need to have support, though (chef, chef-zero, chef-server, chef-provisioning, test-kitchen, third party tools like ChefSpec) 11
a Ruby DSL • Generate a lock file and cache cookbooks with install or update • Upload the policy and the cookbooks with push • Export the policy and cookbooks to a directory 13
cookbooks required • Get the correct version of the cookbooks required • Get the cookbooks to a place the node can download them Account for chef-solo and local-mode Account for chef-server 15
should be tracked in version control • Local development testing can be a hassle • We cache every change to a cookbook • The lock file specifies the shasum to use for upload • This gaurantees consistency in policies being applied • Cookbooks missing from the cache are re-retrieved 16
content • Any cookbook change == the cookbook and policy revisions change • This prevents dangerous behavior, like uploading the same version of a cookbook • Deploy across SDLC with confidence 17
index 61bfd5d..56702da 100644 -‐-‐-‐ a/cookbooks/example/recipes/default.rb +++ b/cookbooks/example/recipes/default.rb @@ -‐1,8 +1,3 @@ -‐# This is a Chef recipe file. It can be used to specify resources which will -‐# apply configuration to a server. -‐ log "Welcome to Chef, #{node["example"]["name"]}!" do level :info end -‐ -‐# For more information, see the documentation: http://docs.getchef.com/ essentials_cookbook_recipes.html 21
policy cookbook-‐dir Expanded run list: recipe[example] Caching Cookbooks... Installing example 1.0.0 Lockfile written to /Users/jtimberman/ Development/sandbox/policyfile-‐demo/cookbook-‐ dir.lock.json 22
the cookbook • This makes it a "new version" • This doesn't absolve users from managing versions in metadata.rb! • Still follow best practices for releasing artifacts - policies aren't applicable to Supermarket or SCM repos 25
• Store the attributes used in that run list • Store the specific version of all cookbook content • Bound to the node • The node is still the authority about itself 26
default source (e.g., supermarket) • Modify any attributes (at the same priority as "role" attributes) • Specify any source options for cookbooks (local path or git sources, specific versions) 27
Expanded run list: recipe[vim], recipe[zsh] Caching Cookbooks... Using vim 1.1.4 Using zsh 1.0.3 Lockfile written to /Users/jtimberman/Development/ sandbox/policyfile-‐demo/Policyfile.lock.json 32
1.0.2' cookbook 'zsh', '~> 1.0.0' # cookbook from a local path cookbook 'zsh', '/Users/jtimberman/dev/cookbooks/zsh' # cookbook from a git repository cookbook 'zsh', git: 'https://github.com/chef-‐cookbooks/zsh' # cookbook from github repository cookbook 'zsh', github: 'chef-‐cookbooks/zsh' # cookbook from the same github repository by a release tag cookbook 'zsh', github: 'chef-‐cookbooks/zsh', tag: '1.0.2' 51
# local/private supermarket server: default_source :supermarket, 'https://supermarket.example.com' # the cookbooks from the current working directory: default_source :chef_repo, File.dirname(__FILE__) # cookbooks from another filesystem location: default_source :chef_repo, "/home/src/cookbook-‐repo" 53
of this writing, otherwise may be in version 4.4.0. https://github.com/sethvargo/chefspec/pull/634 • Use bundler to get the right version • Require the policyfile library in spec_helper 56
is required to have policyfile support for ChefSpec gem 'chefspec', git: 'https://github.com/sethvargo/chefspec', ref: 'cd57e28fdbd59fc26962c0dd3b1809b8841312f3' gem 'chef-‐dk', ‘=> 0.7.0' 57
cookbook • Use ChefDK::ProvisioningData.context • Set convergence_options from the context in the machine options • Take the machine action from the context 61
• "wrapper" cookbooks that only set attributes and include recipes are easy • "roles" and "role cookbooks" simply move the attributes and run list • We plan to create a "role to policyfile" conversion tool 66
roles • Must have certain versions of Chef, ChefDK, Chef Server • Not implemented for knife bootstrap • Cannot “nest” or “include” other policies • Rapidly working towards "1.0 Feature Complete" status 67
constraints • Attributes • Everything kept in lockstep throughout the lifecycle • Consistent workflow commands • Integration with chef provisioning in `chef provision` • Easier to reason about than roles, environments, berksfiles, role cookbooks, different “knife” upload commands, etc 68
lists become a thing • ChefDK: cookbook generate policyfile instead of berksfile, and a policies directory for a repo • ChefSpec (4.4.0): Support for policyfiles • Chef Zero (unknown version): Policy APIs instead of compatibility mode • Chef Analytics, Chef Sync product integration 69 Coming soon - or may have arrived!