Lock an environment's cookbooks

Hey Guys,

Is there any way to take an environment, which currently has no cookbook
version constraints, and set each cookbook version to the latest of whats
deployed on my chef server? Would really suck to have to get the expanded
run list and do “knife node show” on each… Any other way about this ?

-John

"knife cookbook list" will show you all of the cookbooks currently
deployed and the latest versions of each. You can see all the versions
of a particular cookbook with "knife cookbook show FOO". You can then
take those versions and set them in your environment.
http://wiki.opscode.com/display/chef/Environments#Environments-cookbookversions

Thanks,
Matt Ray
Senior Technical Evangelist | Opscode Inc.
matt@opscode.com | (512) 731-2218
Twitter, IRC, GitHub: mattray

On Thu, Jun 21, 2012 at 10:44 PM, John Dyer johntdyer@gmail.com wrote:

Hey Guys,

Is there any way to take an environment, which currently has no cookbook
version constraints, and set each cookbook version to the latest of whats
deployed on my chef server? Would really suck to have to get the expanded
run list and do "knife node show" on each... Any other way about this ?

-John

I've done this once before using shef, and it turns out to be pretty easy.

  1. Fire up shef like so

% shef -z -c ~/.chef/knife.rb

  1. Load your environment

chef > env = Chef::Environment.load('YOUR_ENV_HERE')

  1. Grab your cookbook versions and format to taste.

chef > env.cookbook_versions
=> {"build-essential"=>"= 1.0.0", … }

  1. Include your output in environments/YOUR_ENV_HERE.rb

  2. Upload

% knife environment from file environments/YOUR_ENV_HERE.rb

HTH,

Jeremy

On Jun 21, 2012, at 8:44 PM, John Dyer wrote:

Hey Guys,

Is there any way to take an environment, which currently has no cookbook version constraints, and set each cookbook version to the latest of whats deployed on my chef server? Would really suck to have to get the expanded run list and do "knife node show" on each... Any other way about this ?

-John

Hey Jeremy,

Thanks for the tip, however it didn't appear to work for me, any idea what
I am doing wrong?

Last login: Wed May 30 23:31:39 on ttys021
22:10:45 (production_ec2) jdyer@aleph.local ~ shef -z -c ~/.chef/knife.rb
loading configuration: /Users/jdyer/.chef/knife.rb
Session type: client
Loading.......[Fri, 29 Jun 2012 22:10:52 -0400] INFO: Run List is
[Fri, 29 Jun 2012 22:10:52 -0400] INFO: Run List expands to
....[Fri, 29 Jun 2012 22:10:54 -0400] INFO: Loading cookbooks
done.

This is shef, the Chef shell.
Chef Version: 0.10.10
Configuration Management System Software - Chef Infra | Chef
http://wiki.opscode.com/display/chef/Home

run help' for help, exit' or ^D to quit.

Ohai2u jdyer@aleph.local!
chef > env = Chef::Environment.load('dt_prod')
=> dt_prod
chef > env.cookbook_versions
=> {}
chef >

-John

On Fri, Jun 22, 2012 at 12:16 AM, Jeremy Voorhis jvoorhis@gmail.com wrote:

I've done this once before using shef, and it turns out to be pretty easy.

  1. Fire up shef like so

% shef -z -c ~/.chef/knife.rb

  1. Load your environment

chef > env = Chef::Environment.load('YOUR_ENV_HERE')

  1. Grab your cookbook versions and format to taste.

chef > env.cookbook_versions
=> {"build-essential"=>"= 1.0.0", … }

  1. Include your output in environments/YOUR_ENV_HERE.rb

  2. Upload

% knife environment from file environments/YOUR_ENV_HERE.rb

HTH,

Jeremy

On Jun 21, 2012, at 8:44 PM, John Dyer wrote:

Hey Guys,

Is there any way to take an environment, which currently has no
cookbook version constraints, and set each cookbook version to the latest
of whats deployed on my chef server? Would really suck to have to get the
expanded run list and do "knife node show" on each... Any other way about
this ?

-John

Hey John,

I just use something like this to get a formatted list that will work:

knife cookbook list | awk '{print """$1"" => "= "$2"""}' > new_env.rb

use your favorite editor to properly edit new-env.rb and then knife environment from file to your hearts content.

-sme

On Fri, Jun 29, 2012 at 7:14 PM, John Dyer johntdyer@gmail.com wrote:

Hey Jeremy,

Thanks for the tip, however it didn't appear to work for me, any idea
what I am doing wrong?

Last login: Wed May 30 23:31:39 on ttys021
22:10:45 (production_ec2) jdyer@aleph.local ~ shef -z -c ~/.chef/knife.rb
loading configuration: /Users/jdyer/.chef/knife.rb
Session type: client
Loading.......[Fri, 29 Jun 2012 22:10:52 -0400] INFO: Run List is
[Fri, 29 Jun 2012 22:10:52 -0400] INFO: Run List expands to
....[Fri, 29 Jun 2012 22:10:54 -0400] INFO: Loading cookbooks
done.

This is shef, the Chef shell.
Chef Version: 0.10.10
Configuration Management System Software - Chef Infra | Chef
http://wiki.opscode.com/display/chef/Home

run help' for help, exit' or ^D to quit.

Ohai2u jdyer@aleph.local!
chef > env = Chef::Environment.load('dt_prod')
=> dt_prod
chef > env.cookbook_versions
=> {}
chef >

-John

On Fri, Jun 22, 2012 at 12:16 AM, Jeremy Voorhis jvoorhis@gmail.comwrote:

I've done this once before using shef, and it turns out to be pretty easy.

  1. Fire up shef like so

% shef -z -c ~/.chef/knife.rb

  1. Load your environment

chef > env = Chef::Environment.load('YOUR_ENV_HERE')

  1. Grab your cookbook versions and format to taste.

chef > env.cookbook_versions
=> {"build-essential"=>"= 1.0.0", … }

  1. Include your output in environments/YOUR_ENV_HERE.rb

  2. Upload

% knife environment from file environments/YOUR_ENV_HERE.rb

HTH,

Jeremy

On Jun 21, 2012, at 8:44 PM, John Dyer wrote:

Hey Guys,

Is there any way to take an environment, which currently has no
cookbook version constraints, and set each cookbook version to the latest
of whats deployed on my chef server? Would really suck to have to get the
expanded run list and do "knife node show" on each... Any other way about
this ?

-John