- From: Daniel DeLeo <
>
- To:
- Subject: [chef] Re: Help understanding environment cookbook pattern, and how to generate it?
- Date: Thu, 12 Feb 2015 16:04:52 -0800
On Thursday, February 12, 2015 at 12:51 PM, Fouts, Chris wrote:
>
We are using Chef 12 Enterprise, and have different organizations setup for
>
development and QA.
>
We want to adapt to the Berkshelf way of managing cookbooks. The workflow
>
puts a lot of emphasis on the "environment" cookbook, and I read numerous
>
articles and watch numerous videos about it.
>
http://misheska.com/blog/2013/06/16/getting-started-writing-chef-cookbooks-the-berkshelf-way/
>
>
http://blog.vialstudios.com/the-environment-cookbook-pattern/
>
http://www.hurryupandwait.io/blog/chef-cookbook-dependency-management-and-the-environment-cookbook-pattern
>
>
http://bytearrays.com/manage-chef-cookbooks-organization-repo/
>
...and many more.
>
However, the concept of environment cookbook still eludes me. Can you
>
please shed some light?
>
Say I have a product that has two VMs, a Web VM and a Router VM. Say I have
>
the following cookbooks, (each cookbook is in its own repo and downloaded
>
to the workstation)
>
.berkshelf/default/cookbooks/java
>
.berkshelf/default/cookbooks/apache
>
.berkshelf/default/cookbooks/web-appl
>
.berkshelf/default/cookbooks/iprouter-appl
>
My Web box needs these
>
.berkshelf/default/cookbooks/java
>
.berkshelf/default/cookbooks/apache
>
.berkshelf/default/cookbooks/web-appl
>
My Router box needs these
>
.berkshelf/default/cookbooks/java
>
.berkshelf/default/cookbooks/iprouter-appl
>
I want to setup "dev" and "qa" environments so I can control the versions I
>
want for all the above cookbooks in each environment.
>
Where does the environment cookbook come into play?
>
Should I have the following environment cookbooks (I inferred this from
>
this link http://bytearrays.com/manage-chef-cookbooks-organization-repo)
>
which says environment cookbooks ” Represent a whole node to be
>
installed/managed”
>
- web-dev
>
- web-qa
>
- router-dev
>
- router-qa
Yes, this is how it works. Instead of Chef environments representing the a
stage in the deployment cycle for all of your apps, when you use the
environment cookbook pattern, your Chef environments now represent the
intersection of both a functional role and a deployment stage. So your Chef
environments don’t map to your “real” environments one-to-one (some folks
dislike this but if it works for you, go for it). The advantage of this is
that each kind of application can have the versions of its dependencies
managed independently (e.g., web and router can use different versions of the
java cookbook in prod, which is hard to do safely and easily if you’re
mapping your Chef environments one to one with your real environments).
Berkshelf generates the Chef environment data for you, setting an exact
version pin in the Chef environment which matches the dependency solution in
your lock file.
>
>
If so, what would above cookbook's metadata.rb and Berkshelf.lock file look
>
like?
The blog post you referenced here
http://blog.vialstudios.com/the-environment-cookbook-pattern/ covers this
pretty well. You have a `depends` entry for each cookbook a particular
application needs. E.g., for your example web box, your environment cookbook
depends on java, apache, and web-appl. You can add other version constraints
if you need them (e.g., web and router might only be compatible with
different major versions of the java cookbook, which you’d manage by putting
the correct squiggly constraints ‘~> x.y’ in your depends statements).
>
Chris
>
HTH,
--
Daniel DeLeo
Archive powered by MHonArc 2.6.16.