Let's say I have a Polcyfile.rb in a cookbook called motd:
name 'motd'
default_source :chef_repo, "../"
include_policy "Policyfile", path: "../environment"
run_list 'motd'
and a recipes/default.rb:
file '/etc/motd' do
content node['message']
end
I have another cookbook called environment which has a Policyfile.rb:
name 'environment'
default_source :chef_repo, "../"
run_list 'environment'
It has an empty recipes/default.rb and attributes/default.rb with:
default['message'] = 'i am a message'
I run chef install Policyfile.rb in environment dir to generate the lock file. When I run kitchen converge from motd dir and then kitchen login, I get my expected output to console:
This system is built by the Bento project by Chef Software
More information can be found at https://github.com/chef/bento
i am a message
Now I go and update environment/attributes/default.rb to be
default['message'] = 'i am updated'
I DO NOT run chef update Policyfile.rb for environment and run kitchen converge again from motd. My expectation is that kitchen login will not reflect my update because Policyfile.lock.json in motd has not updated its revision_id for the included environment policy. But much to my surprise I indeed see the updated message in the console. I do see that Policyfile.lock.json has a new root revision_id and that cookbook_locks->environment->identifier has changed. But still, I would think that in this case, if the cookbooks in my dependency Policyfile.rb have changed and don't compute to match the hash of its Policyfile.lock.json revision_id then I should still see the old output or there should be some kind of other warning here.
I guess I'm just trying to understand the concept here more fully. On the one hand, the root revision_id for motd changed so I have achieved idempotency in one sense. But on the other hand the revision_id for environment dependency and its component cookbook don't match. Can someone explain why this makes sense?
revision_idisn't something that freezes the dependency. It does not matter whether it is a cookbook in the run list or a dependency. Only cookbook version is used for locking.Imagine you already have a lock file with for example your
environmentcookbook version and path to the cookbook set.Then if and only if you change the version of the cookbook in
../environment/metadata.rbyou will get the error, stating that particular version of the cookbook is not found. In this case you have to regenerate the lock file.Any other change to the cookbook does not trigger any error. And that is expected behaviour. Imagine, if you had to regenerate lock files for every change you make, that would be a lot of overhead.
Think of
revision_idin policyfile as a version of policyfile. As there is no such concept as backwards compatibility for policyfiles, there is no need to use semantic versioning, and a long unique not so randomly generated string as a version is good enough in this case. And this is whychef show-policywill show you the revisions of policyfiles applied in particular policy groups, to show that this version is deployed to this group.