Search code examples
rubychef-infraprovisioningcookbook

Chef provisioning resource - Run specific version of cookbook


I have a basic machine resource:

machine 'admin' do
  recipe 'my_custom_cookbook::super_secret_recipe'
  ohai_hints 'ec2' => '{}'
  action :converge
  converge true
end

How can I run a specific version (let's say 0.0.5) of my_custom_cookbook::super_secret_recipe against this machine resource?

It seems that just adding

depends 'my_custom_cookbook', '0.0.5'

to the metadata file doesn't work. It always pick the latest version


Solution

  • The provisioning cookbook has no direct relationship to the node it creates so that's why adding that depends wouldn't help. There are three ways to control what version of a cookbook gets used:

    1. Use the new Policyfile system. I don't think cheffish/chef-provisioning have direct support for setting policy name/group yet but you could use the raw_json property probably.
    2. Use an environment. You can set this via the chef_environment property on the machine resource. Check the Chef docs for more detailed info on using environments.
    3. Set it in the run list, recipe 'my_custom_cookbook::super_secret_recipe@0.0.5'. This is a rarely-used feature of Chef and so might not be supported in all places/tools.