# Cookbook versions on node

**URL:** <https://discourse.chef.io/t/cookbook-versions-on-node/2520>\
**Category:** Chef Infra (archive)\
**Created:** [February 8, 2012, 2:36am UTC](https://discourse.chef.io/t/cookbook-versions-on-node/2520 "2012-02-08T02:36:21Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![realityforge](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/realityforge/32/395_2.png) [@realityforge](https://discourse.chef.io/u/realityforge)\
**Post date:** [February 8, 2012, 2:36am UTC](https://discourse.chef.io/t/cookbook-versions-on-node/2520/1 "2012-02-08T02:36:21Z")

</div>

Hi,

I would like to enforce certain cookbook version requirements on  
cookbooks in different environments from within a recipe.

i.e. All cookbooks on “production” environment must have an even minor  
version. (i.e. 10.0.2 is valid but 10.0.3 is not). I also want to  
require that cookbooks be locked or not. (i.e. cookbook referenced in  
production environments must be frozen).

Doing something like

node.run\_list.expand(node.chef\_environment).recipes.with\_versions.each  
do |recipe|  
p recipe  
end

will only include the versions if they have been explicitly set and  
will not allow me to check to see if the version is locked.

Anyone have a good idea how to do this?

–  
Cheers,

Peter Donald

---

<div class="post-metadata">

**Author:** ![AJ\_Christensen](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/aj_christensen/32/525_2.png) [@AJ\_Christensen](https://discourse.chef.io/u/AJ_Christensen)\
**Post date:** [February 8, 2012, 2:41am UTC](https://discourse.chef.io/t/cookbook-versions-on-node/2520/2 "2012-02-08T02:41:12Z")

</div>

Why don't you use environments built in cookbook version locking for  
this, instead of trying to do it from a recipe?

You can make 'freeze' the default by chucking it in your knife.rb

[http://wiki.opscode.com/display/chef/Environments#Environments-cookbookversions](http://wiki.opscode.com/display/chef/Environments#Environments-cookbookversions)

Cheers,

--AJ

On 8 February 2012 15:36, Peter Donald [peter@realityforge.org](mailto:peter@realityforge.org) wrote:

> Hi,
> 
> I would like to enforce certain cookbook version requirements on  
> cookbooks in different environments from within a recipe.
> 
> i.e. All cookbooks on "production" environment must have an even minor  
> version. (i.e. 10.0.2 is valid but 10.0.3 is not). I also want to  
> require that cookbooks be locked or not. (i.e. cookbook referenced in  
> production environments must be frozen).
> 
> Doing something like
> 
> node.run\_list.expand(node.chef\_environment).recipes.with\_versions.each  
> do |recipe|  
> p recipe  
> end
> 
> will only include the versions if they have been explicitly set and  
> will not allow me to check to see if the version is locked.
> 
> Anyone have a good idea how to do this?
> 
> --  
> Cheers,
> 
> Peter Donald

---

<div class="post-metadata">

**Author:** ![realityforge](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/realityforge/32/395_2.png) [@realityforge](https://discourse.chef.io/u/realityforge)\
**Post date:** [February 8, 2012, 2:52am UTC](https://discourse.chef.io/t/cookbook-versions-on-node/2520/3 "2012-02-08T02:52:55Z")

</div>

Hi,

I guess I wasn't exactly clear 🙂

On Wed, Feb 8, 2012 at 1:41 PM, AJ Christensen [aj@junglist.gen.nz](mailto:aj@junglist.gen.nz) wrote:

> Why don't you use environments built in cookbook version locking for

We do this to a small degree atm but want to do it across the board.

Each environment should lock the cookbooks to a particular version.  
Each environment (with the exception? of development) should only  
reference frozen cookbooks.

> this, instead of trying to do it from a recipe?

What I want to do from the recipe is enforce that the above rules are  
followed. I have a recipe that runs at the start of every run that  
checks some assumptions. If any of these assumptions fail the the  
chef run aborts.

--  
Cheers,

Peter Donald

---

<div class="post-metadata">

**Author:** ![KC\_Braunschweig](https://avatars.discourse-cdn.com/v4/letter/k/ea5d25/32.png) [@KC\_Braunschweig](https://discourse.chef.io/u/KC_Braunschweig)\
**Post date:** [February 8, 2012, 5:17am UTC](https://discourse.chef.io/t/cookbook-versions-on-node/2520/4 "2012-02-08T05:17:30Z")

</div>

Interested to hear if people have a way to do this, but what I've  
heard people do is instead have a post-commit hook on your revision  
control that pushes to the server in only the ways you want and then  
prevent people from uploading to the server manually to force them  
through revision control and thus your other limitations.

KC

On Tue, Feb 7, 2012 at 6:52 PM, Peter Donald [peter@realityforge.org](mailto:peter@realityforge.org) wrote:

> Hi,
> 
> I guess I wasn't exactly clear 🙂
> 
> On Wed, Feb 8, 2012 at 1:41 PM, AJ Christensen [aj@junglist.gen.nz](mailto:aj@junglist.gen.nz) wrote:
> 
> > Why don't you use environments built in cookbook version locking for
> 
> We do this to a small degree atm but want to do it across the board.
> 
> Each environment should lock the cookbooks to a particular version.  
> Each environment (with the exception? of development) should only  
> reference frozen cookbooks.
> 
> > this, instead of trying to do it from a recipe?
> 
> What I want to do from the recipe is enforce that the above rules are  
> followed. I have a recipe that runs at the start of every run that  
> checks some assumptions. If any of these assumptions fail the the  
> chef run aborts.
> 
> --  
> Cheers,
> 
> Peter Donald

---

<div class="post-metadata">

**Author:** ![realityforge](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/realityforge/32/395_2.png) [@realityforge](https://discourse.chef.io/u/realityforge)\
**Post date:** [March 16, 2012, 3:11am UTC](https://discourse.chef.io/t/cookbook-versions-on-node/2520/5 "2012-03-16T03:11:54Z")

</div>

Hi,

I eventually got around to looking at this and have started to verify  
that all cookbooks are frozen and have an explicit version if they are  
not in the development environment. I have put the basics of it in a  
gist for any one who is curious...

[https://gist.github.com/2048310](https://gist.github.com/2048310)

On Wed, Feb 8, 2012 at 1:36 PM, Peter Donald [peter@realityforge.org](mailto:peter@realityforge.org) wrote:

> Hi,
> 
> I would like to enforce certain cookbook version requirements on  
> cookbooks in different environments from within a recipe.
> 
> i.e. All cookbooks on "production" environment must have an even minor  
> version. (i.e. 10.0.2 is valid but 10.0.3 is not). I also want to  
> require that cookbooks be locked or not. (i.e. cookbook referenced in  
> production environments must be frozen).
> 
> Doing something like
> 
> node.run\_list.expand(node.chef\_environment).recipes.with\_versions.each  
> do |recipe|  
> p recipe  
> end
> 
> will only include the versions if they have been explicitly set and  
> will not allow me to check to see if the version is locked.
> 
> Anyone have a good idea how to do this?
> 
> --  
> Cheers,
> 
> Peter Donald

--  
Cheers,

Peter Donald
