Reputation: 987
I'm currently using Chef to deploy an instance of Jenkins via the Chef supermarket Jenkins cookbook. I've made quite a few modifications to the _master_war.rb recipe file.
A new version of the Jenkins cookbook is available. My question is; how do I go about updating to the latest version of the cookbook without overwriting / losing all the modifications I've made to my current version of the cookbook?
I've checked out Chef's documentation on cookbook versions, as well as the knife cookbook documentation, but it still isn't very clear to me the proper way to go about updating your cookbooks safely.
Thanks for any guidance.
Upvotes: 0
Views: 270
Reputation: 15784
the best way to update safely is to never modify a community cookbook directly and use a wrapper cookbook.
This wrapper will depends
on the community cookbook on a specific version in its metadata.rb (more details about this here):
depends "jenkins", "~> 2.3"
You will tweak attributes for the community cookbook in the wrapper cookbook attributes files.
They will be loaded after the community cookbooks ones (see attributes precedence for details), you have to keep a special attention on derived attributes (see https://coderanger.net/chef-tips/#5 for a workaround if you're so inclined), if a community cookbook has:
default['jenkins']['version'] = "2.0.1"
default['jenkins']['download_url'] = "https://some.site/artifacts/jenkins-#{node['jenkins']['version']}"
and you wish to just override the version, then you have to redo both attributes in the wrapper cookbook, the download_url
on the second line won't be evaluated again.
It will then include the community cookbook in its recipe and take advantage of the edit_resource
recipe DSL method to modify the community cookbook behavior:
include_recipe 'jenkins::default'
edit_resource(:template, '/etc/jenkins/config.cnf') do
source 'aliases.erb'
cookbook 'aliases'
end
Upvotes: 2