# Confused about environments

**URL:** <https://discourse.chef.io/t/confused-about-environments/5032>\
**Category:** Chef Infra (archive)\
**Created:** [February 14, 2014, 9:40pm UTC](https://discourse.chef.io/t/confused-about-environments/5032 "2014-02-14T21:40:52Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Douglas\_Garstang](https://avatars.discourse-cdn.com/v4/letter/d/c2a13f/32.png) [@Douglas\_Garstang](https://discourse.chef.io/u/Douglas_Garstang)\
**Post date:** [February 14, 2014, 9:40pm UTC](https://discourse.chef.io/t/confused-about-environments/5032/1 "2014-02-14T21:40:52Z")

</div>

I’m missing an important detail with chef environments. I created an  
environment called ‘eu2-prod’ with the knife command, and can view and edit  
it.

In my cookbook I have created the environments directory into which I have  
deposited an environment file called ‘eu2-prod.json’. It looks like this:

{  
“name”: “eu2-prod”,  
“description”: “”,  
“cookbook\_versions”: {  
},  
“json\_class”: “Chef::Environment”,  
“chef\_type”: “environment”,  
“default\_attributes”: {  
},  
“override\_attributes”: {  
}  
}

All this has been uploaded to the chef server. However, when the client  
runs, it can’t find the data from the eu2-prod environment.

Looking at the chef GUI, I’m still confused. The cookbook itself doesn’t  
show the environments/ directory, but rather has a drop-down at the top  
which lets me select which environment I am looking at. No matter which  
environment I pick, ‘None’, ‘\_default’ or ‘eu2-prod’ I can’t see any of the  
data from the environments/eu2-prod.json file.

If I go over to the Environments global section in the UI, also there’s no  
data there. I wouldn’t expect to see any data there anyway, as I imagine  
that’s environment data that’s, err… global in scope.

Thanks,  
Doug

---

<div class="post-metadata">

**Author:** ![JOHN\_HASTY](https://avatars.discourse-cdn.com/v4/letter/j/0ea827/32.png) [@JOHN\_HASTY](https://discourse.chef.io/u/JOHN_HASTY)\
**Post date:** [February 14, 2014, 9:49pm UTC](https://discourse.chef.io/t/confused-about-environments/5032/2 "2014-02-14T21:49:11Z")

</div>

I mistake I make occasionally is to not reset the environment in the node:

{  
“name”: “cheftest1”,  
“chef\_environment”: “cheftest”,  
“normal”: {  
“deployment”: “cheftest”,  
“tags”: [

```
]

```

},  
“run\_list”: [  
“role[dmgr]”,  
“recipe[was::dmgr]”  
]  
}

It seems to get reset to \_default when I bootstrap the node unless I have  
knife{‘environment’]=“cheftest”’ in my knife.rb file.

JOHN HASTY  
Software as a Service - DevOps  
Software Group

Phone: 1-512-804-9968 IBM  
E-mail: [jahasty@us.ibm.com](mailto:jahasty@us.ibm.com)  
2407 S Congress Ave Ste E-350  
Austin, TX 78704  
United States

From: Douglas Garstang [doug.garstang@gmail.com](mailto:doug.garstang@gmail.com)  
To: [chef@lists.opscode.com](mailto:chef@lists.opscode.com),  
Date: 02/14/2014 03:41 PM  
Subject: [chef] Confused about environments.

I’m missing an important detail with chef environments. I created an  
environment called ‘eu2-prod’ with the knife command, and can view and edit  
it.

In my cookbook I have created the environments directory into which I have  
deposited an environment file called ‘eu2-prod.json’. It looks like this:

{  
“name”: “eu2-prod”,  
“description”: “”,  
“cookbook\_versions”: {  
},  
“json\_class”: “Chef::Environment”,  
“chef\_type”: “environment”,  
“default\_attributes”: {  
},  
“override\_attributes”: {  
}  
}

All this has been uploaded to the chef server. However, when the client  
runs, it can’t find the data from the eu2-prod environment.

Looking at the chef GUI, I’m still confused. The cookbook itself doesn’t  
show the environments/ directory, but rather has a drop-down at the top  
which lets me select which environment I am looking at. No matter which  
environment I pick, ‘None’, ‘\_default’ or ‘eu2-prod’ I can’t see any of the  
data from the environments/eu2-prod.json file.

If I go over to the Environments global section in the UI, also there’s no  
data there. I wouldn’t expect to see any data there anyway, as I imagine  
that’s environment data that’s, err… global in scope.

Thanks,  
Doug

---

<div class="post-metadata">

**Author:** ![Douglas\_Garstang](https://avatars.discourse-cdn.com/v4/letter/d/c2a13f/32.png) [@Douglas\_Garstang](https://discourse.chef.io/u/Douglas_Garstang)\
**Post date:** [February 14, 2014, 9:50pm UTC](https://discourse.chef.io/t/confused-about-environments/5032/3 "2014-02-14T21:50:24Z")

</div>

Ok, the plot thickens.

(bitcasa-prod) Douglass-Mac-mini:~ knife-eu2 environment show eu2-prod  
chef\_type: environment  
cookbook\_versions:  
default\_attributes:  
description:  
json\_class: Chef::Environment  
name: eu2-prod  
override\_attributes:

The data isn't even on the server. ☹ No default and no override  
attributes. I'm obviously not uploading the data correctly.

Doug.

On Fri, Feb 14, 2014 at 1:40 PM, Douglas Garstang  
[doug.garstang@gmail.com](mailto:doug.garstang@gmail.com)wrote:

> I'm missing an important detail with chef environments. I created an  
> environment called 'eu2-prod' with the knife command, and can view and edit  
> it.
> 
> In my cookbook I have created the environments directory into which I have  
> deposited an environment file called 'eu2-prod.json'. It looks like this:
> 
> {  
> "name": "eu2-prod",  
> "description": "",  
> "cookbook\_versions": {  
> },  
> "json\_class": "Chef::Environment",  
> "chef\_type": "environment",  
> "default\_attributes": {  
> },  
> "override\_attributes": {  
> }  
> }
> 
> All this has been uploaded to the chef server. However, when the client  
> runs, it can't find the data from the eu2-prod environment.
> 
> Looking at the chef GUI, I'm still confused. The cookbook itself doesn't  
> show the environments/ directory, but rather has a drop-down at the top  
> which lets me select which environment I am looking at. No matter which  
> environment I pick, 'None', '\_default' or 'eu2-prod' I can't see any of the  
> data from the environments/eu2-prod.json file.
> 
> If I go over to the Environments global section in the UI, also there's no  
> data there. I wouldn't expect to see any data there anyway, as I imagine  
> that's environment data that's, err... global in scope.
> 
> Thanks,  
> Doug

--  
Regards,

Douglas Garstang  
[http://www.linkedin.com/in/garstang](http://www.linkedin.com/in/garstang)  
Email: [doug.garstang@gmail.com](mailto:doug.garstang@gmail.com)  
Cell: +1-805-340-5627

---

<div class="post-metadata">

**Author:** ![werebus](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/werebus/32/24_2.png) [@werebus](https://discourse.chef.io/u/werebus)\
**Post date:** [February 14, 2014, 10:28pm UTC](https://discourse.chef.io/t/confused-about-environments/5032/4 "2014-02-14T22:28:16Z")

</div>

From your email it sounded like you were putting your environment file  
_inside_ a cookbook? I might've misunderstood you , but if that's the case,  
that's probably not right. Most people keep their environments in a  
directory in their  
chef-repo[http://docs.opscode.com/essentials\_repository.html](http://docs.opscode.com/essentials_repository.html)and then  
they're uploaded using knife  
environment from file

-Matt Moretti

On Fri, Feb 14, 2014 at 4:50 PM, Douglas Garstang  
[doug.garstang@gmail.com](mailto:doug.garstang@gmail.com)wrote:

> Ok, the plot thickens.
> 
> (bitcasa-prod) Douglass-Mac-mini:~ knife-eu2 environment show eu2-prod  
> chef\_type: environment  
> cookbook\_versions:  
> default\_attributes:  
> description:  
> json\_class: Chef::Environment  
> name: eu2-prod  
> override\_attributes:
> 
> The data isn't even on the server. ☹ No default and no override  
> attributes. I'm obviously not uploading the data correctly.
> 
> Doug.
> 
> On Fri, Feb 14, 2014 at 1:40 PM, Douglas Garstang \<[doug.garstang@gmail.com](mailto:doug.garstang@gmail.com)
> 
> > wrote:
> 
> > I'm missing an important detail with chef environments. I created an  
> > environment called 'eu2-prod' with the knife command, and can view and edit  
> > it.
> > 
> > In my cookbook I have created the environments directory into which I  
> > have deposited an environment file called 'eu2-prod.json'. It looks like  
> > this:
> > 
> > {  
> > "name": "eu2-prod",  
> > "description": "",  
> > "cookbook\_versions": {  
> > },  
> > "json\_class": "Chef::Environment",  
> > "chef\_type": "environment",  
> > "default\_attributes": {  
> > },  
> > "override\_attributes": {  
> > }  
> > }
> > 
> > All this has been uploaded to the chef server. However, when the client  
> > runs, it can't find the data from the eu2-prod environment.
> > 
> > Looking at the chef GUI, I'm still confused. The cookbook itself doesn't  
> > show the environments/ directory, but rather has a drop-down at the top  
> > which lets me select which environment I am looking at. No matter which  
> > environment I pick, 'None', '\_default' or 'eu2-prod' I can't see any of the  
> > data from the environments/eu2-prod.json file.
> > 
> > If I go over to the Environments global section in the UI, also there's  
> > no data there. I wouldn't expect to see any data there anyway, as I imagine  
> > that's environment data that's, err... global in scope.
> > 
> > Thanks,  
> > Doug
> 
> --  
> Regards,
> 
> Douglas Garstang  
> [http://www.linkedin.com/in/garstang](http://www.linkedin.com/in/garstang)  
> Email: [doug.garstang@gmail.com](mailto:doug.garstang@gmail.com)  
> Cell: +1-805-340-5627

---

<div class="post-metadata">

**Author:** ![Douglas\_Garstang](https://avatars.discourse-cdn.com/v4/letter/d/c2a13f/32.png) [@Douglas\_Garstang](https://discourse.chef.io/u/Douglas_Garstang)\
**Post date:** [February 14, 2014, 10:51pm UTC](https://discourse.chef.io/t/confused-about-environments/5032/5 "2014-02-14T22:51:23Z")

</div>

Matthew,

Since we have one chef-repo per cookbook, it seemed to make perfect sense  
to put the environment into the cookbook. I've since realised that's not  
going to work as updating the environment from one cookbook blows updates  
from the previous one away.

I'm trying to find a way to decouple the attributes between cookbooks. See  
my subsequent post on that. It seems like environments are no better than  
roles for that. We need one big nasty json file in our main per location.

Doug.

On Fri, Feb 14, 2014 at 2:28 PM, Matthew Moretti [werebus@gmail.com](mailto:werebus@gmail.com) wrote:

> From your email it sounded like you were putting your environment file  
> _inside_ a cookbook? I might've misunderstood you , but if that's the  
> case, that's probably not right. Most people keep their environments in a  
> directory in their chef-repo[http://docs.opscode.com/essentials\_repository.html](http://docs.opscode.com/essentials_repository.html)and then they're uploaded using knife  
> environment from file
> 
> -Matt Moretti
> 
> On Fri, Feb 14, 2014 at 4:50 PM, Douglas Garstang \<[doug.garstang@gmail.com](mailto:doug.garstang@gmail.com)
> 
> > wrote:
> 
> > Ok, the plot thickens.
> > 
> > (bitcasa-prod) Douglass-Mac-mini:~ knife-eu2 environment show eu2-prod  
> > chef\_type: environment  
> > cookbook\_versions:  
> > default\_attributes:  
> > description:  
> > json\_class: Chef::Environment  
> > name: eu2-prod  
> > override\_attributes:
> > 
> > The data isn't even on the server. ☹ No default and no override  
> > attributes. I'm obviously not uploading the data correctly.
> > 
> > Doug.
> > 
> > On Fri, Feb 14, 2014 at 1:40 PM, Douglas Garstang \<  
> > [doug.garstang@gmail.com](mailto:doug.garstang@gmail.com)\> wrote:
> > 
> > > I'm missing an important detail with chef environments. I created an  
> > > environment called 'eu2-prod' with the knife command, and can view and edit  
> > > it.
> > > 
> > > In my cookbook I have created the environments directory into which I  
> > > have deposited an environment file called 'eu2-prod.json'. It looks like  
> > > this:
> > > 
> > > {  
> > > "name": "eu2-prod",  
> > > "description": "",  
> > > "cookbook\_versions": {  
> > > },  
> > > "json\_class": "Chef::Environment",  
> > > "chef\_type": "environment",  
> > > "default\_attributes": {  
> > > },  
> > > "override\_attributes": {  
> > > }  
> > > }
> > > 
> > > All this has been uploaded to the chef server. However, when the client  
> > > runs, it can't find the data from the eu2-prod environment.
> > > 
> > > Looking at the chef GUI, I'm still confused. The cookbook itself doesn't  
> > > show the environments/ directory, but rather has a drop-down at the top  
> > > which lets me select which environment I am looking at. No matter which  
> > > environment I pick, 'None', '\_default' or 'eu2-prod' I can't see any of the  
> > > data from the environments/eu2-prod.json file.
> > > 
> > > If I go over to the Environments global section in the UI, also there's  
> > > no data there. I wouldn't expect to see any data there anyway, as I imagine  
> > > that's environment data that's, err... global in scope.
> > > 
> > > Thanks,  
> > > Doug
> > 
> > --  
> > Regards,
> > 
> > Douglas Garstang  
> > [http://www.linkedin.com/in/garstang](http://www.linkedin.com/in/garstang)  
> > Email: [doug.garstang@gmail.com](mailto:doug.garstang@gmail.com)  
> > Cell: +1-805-340-5627

--  
Regards,

Douglas Garstang  
[http://www.linkedin.com/in/garstang](http://www.linkedin.com/in/garstang)  
Email: [doug.garstang@gmail.com](mailto:doug.garstang@gmail.com)  
Cell: +1-805-340-5627

---

<div class="post-metadata">

**Author:** ![Morgan\_Blackthorne](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/morgan_blackthorne/32/100_2.png) [@Morgan\_Blackthorne](https://discourse.chef.io/u/Morgan_Blackthorne)\
**Post date:** [February 14, 2014, 11:19pm UTC](https://discourse.chef.io/t/confused-about-environments/5032/6 "2014-02-14T23:19:53Z")

</div>

You're usually the one talking about (or bitching about) corner cases in  
#Chef Infra (archive). I think what you might need to do is take a step back, itemize your  
goals, and ask the best way to achieve them. Because it seems like you're  
trying to fit a round peg in a square hole, and the solution isn't just to  
hammer at it, it's to see if you need to change your approach.

Comments from someone who had you on ignore for a while because you  
couldn't get past the fact that Chef was written in Ruby. You're asking  
more reasonable questions these days, but I'm not sure you're using chef in  
ways it's intended for.

On Friday, February 14, 2014, Douglas Garstang [doug.garstang@gmail.com](mailto:doug.garstang@gmail.com)  
wrote:

> Matthew,
> 
> Since we have one chef-repo per cookbook, it seemed to make perfect sense  
> to put the environment into the cookbook. I've since realised that's not  
> going to work as updating the environment from one cookbook blows updates  
> from the previous one away.
> 
> I'm trying to find a way to decouple the attributes between cookbooks. See  
> my subsequent post on that. It seems like environments are no better than  
> roles for that. We need one big nasty json file in our main per location.
> 
> Doug.
> 
> On Fri, Feb 14, 2014 at 2:28 PM, Matthew Moretti [werebus@gmail.com](mailto:werebus@gmail.com)wrote:
> 
> From your email it sounded like you were putting your environment file  
> _inside_ a cookbook? I might've misunderstood you , but if that's the  
> case, that's probably not right. Most people keep their environments in a  
> directory in their chef-repo[http://docs.opscode.com/essentials\_repository.html](http://docs.opscode.com/essentials_repository.html)and then they're uploaded using knife  
> environment from file
> 
> -Matt Moretti
> 
> On Fri, Feb 14, 2014 at 4:50 PM, Douglas Garstang \<[doug.garstang@gmail.com](mailto:doug.garstang@gmail.com)
> 
> > wrote:
> 
> Ok, the plot thickens.
> 
> (bitcasa-prod) Douglass-Mac-mini:~ knife-eu2 environment show eu2-prod  
> chef\_type: environment  
> cookbook\_versions:  
> default\_attributes:  
> description:  
> json\_class: Chef::Environment  
> name: eu2-prod  
> override\_attributes:
> 
> The data isn't even on the server. ☹ No default and no override  
> attributes. I'm obviously not uploading the data correctly.
> 
> Doug.
> 
> On Fri, Feb 14, 2014 at 1:40 PM, Douglas Garstang \<[doug.garstang@gmail.com](mailto:doug.garstang@gmail.com)
> 
> > wrote:
> 
> I'm missing an important detail with chef environments. I created an  
> environment called 'eu2-prod' with the knife command, and can view and edit  
> it.
> 
> In my cookbook I have created the environments directory into which I have  
> deposited an environment file called 'eu2-prod.json'. It looks like this:
> 
> {  
> "name": "eu2-prod",  
> "description": "",  
> "cookbook\_versions": {  
> },  
> "json\_class": "Chef::Environment",  
> "chef\_type": "environment",  
> "default\_attributes": {  
> },  
> "override\_attributes": {  
> }  
> }
> 
> All this has been uploaded to the chef server. However, when the client  
> runs, it can't find the data from the eu2-prod environment.
> 
> Looking at the chef GUI, I'm still confused. The cookbook itself doesn't  
> show the environments/ directory, but rather has a drop-down at the top  
> which lets me select which environment I am looking at. No matter which  
> environment I pick, 'None', '\_default' or 'eu2-prod' I can't see any of the  
> data from the environments/eu2-prod.json file.
> 
> If I go over to the Environments global section in the UI, also there's no  
> data there. I wouldn't expect to see any data there anyway, as I imagine  
> that's environment data that's, err... global in scope.
> 
> Thanks,  
> Doug
> 
> --  
> Regards,
> 
> Douglas Garstang  
> [http://www.linkedin.com/in/garstang](http://www.linkedin.com/in/garstang)  
> Email: [doug.garstang@gmail.com](mailto:doug.garstang@gmail.com)  
> Cell: +1-805-340-5627
> 
> --  
> Regards,
> 
> Douglas Garstang  
> [http://www.linkedin.com/in/garstang](http://www.linkedin.com/in/garstang)  
> Email:

## --

~_~ StormeRider ~_~

"Every world needs its heroes [...] They inspire us to be better than we  
are. And they protect from the darkness that's just around the corner."

(from Smallville Season 6x1: "Zod")

On why I hate the phrase "that's so lame"... [http://bit.ly/Ps3uSS](http://bit.ly/Ps3uSS)

---

<div class="post-metadata">

**Author:** ![Douglas\_Garstang](https://avatars.discourse-cdn.com/v4/letter/d/c2a13f/32.png) [@Douglas\_Garstang](https://discourse.chef.io/u/Douglas_Garstang)\
**Post date:** [February 15, 2014, 12:17am UTC](https://discourse.chef.io/t/confused-about-environments/5032/7 "2014-02-15T00:17:49Z")

</div>

Morgan,

Less attempts would be made to try and fit square pegs into square holes if  
I had a body of knowledge to learn from. Some published best practices  
would be most beneficial.

One of the problems I am trying to solve is to make cookbooks less fragile.  
Cookbook development is in a high state of flux. An attribute defined in a  
role may be used by more than one cookbook. Changing that reference has the  
potential to break multiple cookbooks.What is the correct approach here? Is  
the best practice to make single references to some common attributes or to  
duplicate them? Again, some best practices guidelines would be helpful.

I'll use the example of a mysql server. Currently it's defined once per  
location, because that made the most sense at the time. If I change it name  
in the role, the cookbooks that use it break. I could use chef search  
instead but that doesn't work with vagrant and chef solo as far as I know.  
If I tested in a full chef server environment, I would need to bring up the  
mysql server and every other node required just to test that the attributes  
were filled out correctly.

You could of course say 'don't do that'. Don't touch the mysql attribute.  
Ok, but it's just an example of how the cookbooks are coupled. The same  
mistake could easily be made with any other attribute at any time. I am  
trying to decouple the cookbooks.

Another issue is that test kitchen, as far as I can tell again, does not  
work with roles. You must take all the attributes from your role and  
manually transcribe it into the kitchen.yml file, which in my mind ins't a  
very good test. That is not going to catch errors like the mysql example  
mentioned above.

Douglas.

On Fri, Feb 14, 2014 at 3:19 PM, Morgan Blackthorne  
[stormerider@gmail.com](mailto:stormerider@gmail.com)wrote:

> You're usually the one talking about (or bitching about) corner cases in  
> #Chef Infra (archive). I think what you might need to do is take a step back, itemize your  
> goals, and ask the best way to achieve them. Because it seems like you're  
> trying to fit a round peg in a square hole, and the solution isn't just to  
> hammer at it, it's to see if you need to change your approach.
> 
> Comments from someone who had you on ignore for a while because you  
> couldn't get past the fact that Chef was written in Ruby. You're asking  
> more reasonable questions these days, but I'm not sure you're using chef in  
> ways it's intended for.
> 
> On Friday, February 14, 2014, Douglas Garstang [doug.garstang@gmail.com](mailto:doug.garstang@gmail.com)  
> wrote:
> 
> > Matthew,
> > 
> > Since we have one chef-repo per cookbook, it seemed to make perfect sense  
> > to put the environment into the cookbook. I've since realised that's not  
> > going to work as updating the environment from one cookbook blows updates  
> > from the previous one away.
> > 
> > I'm trying to find a way to decouple the attributes between cookbooks.  
> > See my subsequent post on that. It seems like environments are no better  
> > than roles for that. We need one big nasty json file in our main per  
> > location.
> > 
> > Doug.
> > 
> > On Fri, Feb 14, 2014 at 2:28 PM, Matthew Moretti [werebus@gmail.com](mailto:werebus@gmail.com)wrote:
> > 
> > From your email it sounded like you were putting your environment file  
> > _inside_ a cookbook? I might've misunderstood you , but if that's the  
> > case, that's probably not right. Most people keep their environments in a  
> > directory in their chef-repo[http://docs.opscode.com/essentials\_repository.html](http://docs.opscode.com/essentials_repository.html)and then they're uploaded using knife  
> > environment from file
> > 
> > -Matt Moretti
> > 
> > On Fri, Feb 14, 2014 at 4:50 PM, Douglas Garstang \<  
> > [doug.garstang@gmail.com](mailto:doug.garstang@gmail.com)\> wrote:
> > 
> > Ok, the plot thickens.
> > 
> > (bitcasa-prod) Douglass-Mac-mini:~ knife-eu2 environment show eu2-prod  
> > chef\_type: environment  
> > cookbook\_versions:  
> > default\_attributes:  
> > description:  
> > json\_class: Chef::Environment  
> > name: eu2-prod  
> > override\_attributes:
> > 
> > The data isn't even on the server. ☹ No default and no override  
> > attributes. I'm obviously not uploading the data correctly.
> > 
> > Doug.
> > 
> > On Fri, Feb 14, 2014 at 1:40 PM, Douglas Garstang \<  
> > [doug.garstang@gmail.com](mailto:doug.garstang@gmail.com)\> wrote:
> > 
> > I'm missing an important detail with chef environments. I created an  
> > environment called 'eu2-prod' with the knife command, and can view and edit  
> > it.
> > 
> > In my cookbook I have created the environments directory into which I  
> > have deposited an environment file called 'eu2-prod.json'. It looks like  
> > this:
> > 
> > {  
> > "name": "eu2-prod",  
> > "description": "",  
> > "cookbook\_versions": {  
> > },  
> > "json\_class": "Chef::Environment",  
> > "chef\_type": "environment",  
> > "default\_attributes": {  
> > },  
> > "override\_attributes": {  
> > }  
> > }
> > 
> > All this has been uploaded to the chef server. However, when the client  
> > runs, it can't find the data from the eu2-prod environment.
> > 
> > Looking at the chef GUI, I'm still confused. The cookbook itself doesn't  
> > show the environments/ directory, but rather has a drop-down at the top  
> > which lets me select which environment I am looking at. No matter which  
> > environment I pick, 'None', '\_default' or 'eu2-prod' I can't see any of the  
> > data from the environments/eu2-prod.json file.
> > 
> > If I go over to the Environments global section in the UI, also there's  
> > no data there. I wouldn't expect to see any data there anyway, as I imagine  
> > that's environment data that's, err... global in scope.
> > 
> > Thanks,  
> > Doug
> > 
> > --  
> > Regards,
> > 
> > Douglas Garstang  
> > [http://www.linkedin.com/in/garstang](http://www.linkedin.com/in/garstang)  
> > Email: [doug.garstang@gmail.com](mailto:doug.garstang@gmail.com)  
> > Cell: +1-805-340-5627
> > 
> > --  
> > Regards,
> > 
> > Douglas Garstang  
> > [http://www.linkedin.com/in/garstang](http://www.linkedin.com/in/garstang)  
> > Email:
> 
> ## --
> 
> ~_~ StormeRider ~_~
> 
> "Every world needs its heroes [...] They inspire us to be better than we  
> are. And they protect from the darkness that's just around the corner."
> 
> (from Smallville Season 6x1: "Zod")
> 
> On why I hate the phrase "that's so lame"... [http://bit.ly/Ps3uSS](http://bit.ly/Ps3uSS)

--  
Regards,

Douglas Garstang  
[http://www.linkedin.com/in/garstang](http://www.linkedin.com/in/garstang)  
Email: [doug.garstang@gmail.com](mailto:doug.garstang@gmail.com)  
Cell: +1-805-340-5627

---

<div class="post-metadata">

**Author:** ![David\_Petzel](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/david_petzel/32/38_2.png) [@David\_Petzel](https://discourse.chef.io/u/David_Petzel)\
**Post date:** [February 15, 2014, 1:52am UTC](https://discourse.chef.io/t/confused-about-environments/5032/8 "2014-02-15T01:52:17Z")

</div>

On Fri, Feb 14, 2014 at 7:17 PM, Douglas Garstang  
[doug.garstang@gmail.com](mailto:doug.garstang@gmail.com)wrote:

> Morgan,
> 
> Another issue is that test kitchen, as far as I can tell again, does not  
> work with roles. You must take all the attributes from your role and  
> manually transcribe it into the kitchen.yml file, which in my mind ins't a  
> very good test. That is not going to catch errors like the mysql example  
> mentioned above.

I have not personally used it, but just the other day I stumbled across the  
fact that test-kitchen does actually support roles, although its not  
clearly documented (that I found):

> <https://github.com/test-kitchen/test-kitchen/issues/129>
>
> I have some logic in my LWRP that I'd like to test that requires a data bag. Usu…ally I would accomplish this by setting \`chef.data\_bags\_path\` in my Vagrantfile.
> \- I think https://github.com/opscode/test-kitchen/pull/124 might mean that a data\_bags directory in my cookbook-under-test will be ignored. Maybe that can be added back in?
> \- Add some sort of syntax to the .ktichen.yml file or just default to generating the test-kitchen Vagrantfiles with the \`chef.data\_bags\_path\` property set to the uploaded databags.

---

<div class="post-metadata">

**Author:** ![Morgan\_Blackthorne](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/morgan_blackthorne/32/100_2.png) [@Morgan\_Blackthorne](https://discourse.chef.io/u/Morgan_Blackthorne)\
**Post date:** [February 15, 2014, 2:18am UTC](https://discourse.chef.io/t/confused-about-environments/5032/9 "2014-02-15T02:18:57Z")

</div>

Again, you're focusing on how to get there rather than stating where you  
need to go and why.

And yes, the tooling around Chef is in flux. Best practices are still  
evolving. This is something Chef is aware of and aiming to address via gap  
coverage and documentation as they head towards Chef 12. The Chef 10  
standard of knife cookbook upload clearly doesn't cut it-- but. Chef  
doesn't maintain any of the extra tools currently, they are all third  
party. (And I think for the most part, that's the way they intend it to  
maintain but they may contribute resources to shore up projects.) Again,  
that's something they want to nail down process wise for 12, where a clear  
process for uploading and testing can be defined, abstracted from the  
tooling used (ie, librarian vs berkshelf, vagrant vs chef-zero vs vagabond,  
BAtS vs chefspec, etc),

In the meantime, the bigger picture you can convey, the better quality  
architectural advice you will be given.

On Friday, February 14, 2014, Douglas Garstang [doug.garstang@gmail.com](mailto:doug.garstang@gmail.com)  
wrote:

> Morgan,
> 
> Less attempts would be made to try and fit square pegs into square holes  
> if I had a body of knowledge to learn from. Some published best practices  
> would be most beneficial.
> 
> One of the problems I am trying to solve is to make cookbooks less  
> fragile. Cookbook development is in a high state of flux. An attribute  
> defined in a role may be used by more than one cookbook. Changing that  
> reference has the potential to break multiple cookbooks.What is the correct  
> approach here? Is the best practice to make single references to some  
> common attributes or to duplicate them? Again, some best practices  
> guidelines would be helpful.
> 
> I'll use the example of a mysql server. Currently it's defined once per  
> location, because that made the most sense at the time. If I change it name  
> in the role, the cookbooks that use it break. I could use chef search  
> instead but that doesn't work with vagrant and chef solo as far as I know.  
> If I tested in a full chef server environment, I would need to bring up the  
> mysql server and every other node required just to test that the attributes  
> were filled out correctly.
> 
> You could of course say 'don't do that'. Don't touch the mysql attribute.  
> Ok, but it's just an example of how the cookbooks are coupled. The same  
> mistake could easily be made with any other attribute at any time. I am  
> trying to decouple the cookbooks.
> 
> Another issue is that test kitchen, as far as I can tell again, does not  
> work with roles. You must take all the attributes from your role and  
> manually transcribe it into the kitchen.yml file, which in my mind ins't a  
> very good test. That is not going to catch errors like the mysql example  
> mentioned above.
> 
> Douglas.
> 
> On Fri, Feb 14, 2014 at 3:19 PM, Morgan Blackthorne \<[stormerider@gmail.com](mailto:stormerider@gmail.com)
> 
> > wrote:
> 
> You're usually the one talking about (or bitching about) corner cases in  
> #Chef Infra (archive). I think what you might need to do is take a step back, itemize your  
> goals, and ask the best way to achieve them. Because it seems like you're  
> trying to fit a round peg in a square hole, and the solution isn't just to  
> hammer at it, it's to see if you need to change your approach.
> 
> Comments from someone who had you on ignore for a while because you  
> couldn't get past the fact that Chef was written in Ruby. You're asking  
> more reasonable questions these days, but I'm not sure you're using chef in  
> ways it's intended for.
> 
> On Friday, February 14, 2014, Douglas Garstang [doug.garstang@gmail.com](mailto:doug.garstang@gmail.com)  
> wrote:
> 
> Matthew,
> 
> Since we have one chef-repo per cookbook, it seemed to make perfect sense  
> to put the environment into the cookbook. I've since realised that's not  
> going to work as updating the environment from one cookbook blows updates  
> from the previous one away.
> 
> I'm trying to find a way to decouple the attributes between cookbooks. See  
> my subsequent post on that. It seems like environments are no better than  
> roles for that. We need one big nasty json file in our main per location.
> 
> Doug.
> 
> On Fri, Feb 14, 2014 at 2:28 PM, Matthew Moretti [werebus@gmail.com](mailto:werebus@gmail.com)wrote:
> 
> From your email it sounded like you were putting your environment file  
> _inside_ a cookbook? I might've misunderstood you , but if that's the  
> case, that's probably not right. Most people keep their environments in a  
> directory in their chef-repo[http://docs.opscode.com/essentials\_repository.html](http://docs.opscode.com/essentials_repository.html)and then they're uploaded using knife  
> environment from file
> 
> -Matt Moretti
> 
> On Fri, Feb 14, 2014 at 4:50 PM, Douglas Garstang \<[doug.garstang@gmail.com](mailto:doug.garstang@gmail.com)
> 
> > wrote:
> 
> Ok, the plot thickens.
> 
> (bitcasa-prod) Douglass-Mac-mini:~ knife-eu2 environment show eu2-prod  
> chef\_type: environment  
> cookbook\_versions:  
> default\_attributes:  
> description:  
> json\_class: Chef::Environment  
> name: eu2-prod  
> override\_attributes:
> 
> The data isn't even on the server. ☹ No default and no override  
> attributes. I'm obviously not uploading the data correctly.
> 
> Doug.
> 
> On Fri, Feb 14, 2014 at 1:40 PM, Douglas Garstang \<[doug.garstang@gmail.com](mailto:doug.garstang@gmail.com)
> 
> > wrote:
> 
> I'm missing an important detail with chef environments. I created an  
> environment called 'eu2-prod' with the knife command, and can view and edit  
> it.
> 
> In my cookbook I have created the environments directory into which I have  
> deposited an environment file called 'eu2-prod.json'. It looks like this:
> 
> {  
> "name": "eu2-prod",  
> "description": "",  
> "cookbook\_versions": {  
> },  
> "json\_class": "Chef::Environment",  
> "chef\_type": "environment",  
> "default\_attributes": {  
> },  
> "override\_attributes": {  
> }  
> }
> 
> All this has been uploaded to the chef server. However, when the client  
> runs, it can't find the data from the eu2-prod environment.

## --

~_~ StormeRider ~_~

"Every world needs its heroes [...] They inspire us to be better than we  
are. And they protect from the darkness that's just around the corner."

(from Smallville Season 6x1: "Zod")

On why I hate the phrase "that's so lame"... [http://bit.ly/Ps3uSS](http://bit.ly/Ps3uSS)

---

<div class="post-metadata">

**Author:** ![Larry\_Wright](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/larry_wright/32/177_2.png) [@Larry\_Wright](https://discourse.chef.io/u/Larry_Wright)\
**Post date:** [February 15, 2014, 4:05am UTC](https://discourse.chef.io/t/confused-about-environments/5032/10 "2014-02-15T04:05:08Z")

</div>

Hi Doug,

Environments are solely global in nature, so that file needs to go in your top-level environments directory (and uploaded to your Chef server). I think you’re looking at them backwards. Environments are containers (think development, staging, production) where you may want to have different versions of a cookbook, or different attributes. Typical use cases are things like having a different set of hostnames or credentials that you use in staging vs. production, or locking your production environment to a specific version of a cookbook so that you don’t inadvertently release something before it’s been tested thoroughly.

This presentation by Seth Vargo may help clear it up, but feel free to ask more questions if I didn’t explain it well enough: [https://speakerdeck.com/sethvargo/chef-plus-environments-equals-safer-infrastructure](https://speakerdeck.com/sethvargo/chef-plus-environments-equals-safer-infrastructure)

–  
Larry Wright  
@larrywright

On February 14, 2014 at 3:41:09 PM, Douglas Garstang ([doug.garstang@gmail.com](mailto:doug.garstang@gmail.com)) wrote:

I’m missing an important detail with chef environments. I created an environment called ‘eu2-prod’ with the knife command, and can view and edit it.

In my cookbook I have created the environments directory into which I have deposited an environment file called ‘eu2-prod.json’. It looks like this:

{  
“name”: “eu2-prod”,  
“description”: “”,  
“cookbook\_versions”: {  
},  
“json\_class”: “Chef::Environment”,  
“chef\_type”: “environment”,  
“default\_attributes”: {  
},  
“override\_attributes”: {  
}  
}

All this has been uploaded to the chef server. However, when the client runs, it can’t find the data from the eu2-prod environment.

Looking at the chef GUI, I’m still confused. The cookbook itself doesn’t show the environments/ directory, but rather has a drop-down at the top which lets me select which environment I am looking at. No matter which environment I pick, ‘None’, ‘\_default’ or ‘eu2-prod’ I can’t see any of the data from the environments/eu2-prod.json file.

If I go over to the Environments global section in the UI, also there’s no data there. I wouldn’t expect to see any data there anyway, as I imagine that’s environment data that’s, err… global in scope.

Thanks,  
Doug

---

<div class="post-metadata">

**Author:** ![BradKnowles](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/bradknowles/32/99_2.png) [@BradKnowles](https://discourse.chef.io/u/BradKnowles)\
**Post date:** [February 15, 2014, 6:37pm UTC](https://discourse.chef.io/t/confused-about-environments/5032/11 "2014-02-15T18:37:09Z")

</div>

On Feb 14, 2014, at 8:18 PM, Morgan Blackthorne [stormerider@gmail.com](mailto:stormerider@gmail.com) wrote:

> And yes, the tooling around Chef is in flux. Best practices are still evolving.

Especially around testing.

> Again, that's something they want to nail down process wise for 12, where a clear process for uploading and testing can be defined, abstracted from the tooling used (ie, librarian vs berkshelf, vagrant vs chef-zero vs vagabond, BAtS vs chefspec, etc),

And even more confusing can be the issue where it's not exactly vagrant vs. chef-zero, but maybe vagrant+chef-solo vs. vagrant+chef-zero, or ChefSpec on one platform vs. ChefSpec on another platform, or whatever.

Right now, there's a lot of work you have to do on your own to figure out what will work best in what circumstances -- and you may discover that will change over relatively short periods of time as the tools continue to evolve.

--  
Brad Knowles [brad@shub-internet.org](mailto:brad@shub-internet.org)  
LinkedIn Profile: [http://tinyurl.com/y8kpxu](http://tinyurl.com/y8kpxu)

---

<div class="post-metadata">

**Author:** ![Douglas\_Garstang](https://avatars.discourse-cdn.com/v4/letter/d/c2a13f/32.png) [@Douglas\_Garstang](https://discourse.chef.io/u/Douglas_Garstang)\
**Post date:** [February 16, 2014, 11:21pm UTC](https://discourse.chef.io/t/confused-about-environments/5032/12 "2014-02-16T23:21:32Z")

</div>

Larry,

Thanks. I understand all that.

At the time, this statement from the documentation made perfect sense given  
that in our environment we have one git repo per chef repo.

"A Ruby file for each non-default environment must exist in the  
environments/ subdirectory of the chef-repo. "

I since have realised thats' not quite true. In any case, roles and  
environments both don't address the fact that if I define a common  
attribute in a role or an environment, that is used by multiple cookbooks,  
and I change that attribute name, all the cookbooks that refer to it will  
break.

This is why I wanted to contain the attribute (and all it's 'environments'  
solely within the cookbook.

For example, let's say I define this in a role somewhere.

"mysql\_server": {  
'US1": "server1",  
"US2": "server2",  
"EU1": "server3",  
....  
}

Now lets also say 5 cookbooks use this attribute. Change "mysql\_server" to  
"mysql\_host" and those cookbooks all break. Instead, if each cookbook  
defined it's own reference to the mysql server for each location, changing  
one would not break any others. Following this approach would seem to make  
cookbooks a lot less brittle at the expense of a little more duplication of  
data.

Until recently I thought test kitchen couldn't use roles. Maybe it can now.  
I need to check that. Putting the attributes into the cookbook would also  
seem to make test kitchen more reliable, as the attributes would come  
directly from the cookbook. You wouldn't need to copy and paste them from a  
role.

Doug.

Doug

On Fri, Feb 14, 2014 at 8:05 PM, Larry Wright [larrywright@gmail.com](mailto:larrywright@gmail.com) wrote:

> Hi Doug,
> 
> Environments are solely global in nature, so that file needs to go in your  
> top-level environments directory (and uploaded to your Chef server). I  
> think you're looking at them backwards. Environments are containers (think  
> development, staging, production) where you may want to have different  
> versions of a cookbook, or different attributes. Typical use cases are  
> things like having a different set of hostnames or credentials that you use  
> in staging vs. production, or locking your production environment to a  
> specific version of a cookbook so that you don't inadvertently release  
> something before it's been tested thoroughly.
> 
> This presentation by Seth Vargo may help clear it up, but feel free to ask  
> more questions if I didn't explain it well enough:  
> [https://speakerdeck.com/sethvargo/chef-plus-environments-equals-safer-infrastructure](https://speakerdeck.com/sethvargo/chef-plus-environments-equals-safer-infrastructure)
> 
> --  
> Larry Wright  
> @larrywright [http://twitter.com/larrywright](http://twitter.com/larrywright)
> 
> On February 14, 2014 at 3:41:09 PM, Douglas Garstang (  
> [doug.garstang@gmail.com](mailto:doug.garstang@gmail.com) //doug.garstang@gmail.com) wrote:
> 
> I'm missing an important detail with chef environments. I created an  
> environment called 'eu2-prod' with the knife command, and can view and edit  
> it.
> 
> In my cookbook I have created the environments directory into which I have  
> deposited an environment file called 'eu2-prod.json'. It looks like this:
> 
> {  
> "name": "eu2-prod",  
> "description": "",  
> "cookbook\_versions": {  
> },  
> "json\_class": "Chef::Environment",  
> "chef\_type": "environment",  
> "default\_attributes": {  
> },  
> "override\_attributes": {  
> }  
> }
> 
> All this has been uploaded to the chef server. However, when the client  
> runs, it can't find the data from the eu2-prod environment.
> 
> Looking at the chef GUI, I'm still confused. The cookbook itself doesn't  
> show the environments/ directory, but rather has a drop-down at the top  
> which lets me select which environment I am looking at. No matter which  
> environment I pick, 'None', '\_default' or 'eu2-prod' I can't see any of the  
> data from the environments/eu2-prod.json file.
> 
> If I go over to the Environments global section in the UI, also there's no  
> data there. I wouldn't expect to see any data there anyway, as I imagine  
> that's environment data that's, err... global in scope.
> 
> Thanks,  
> Doug

--  
Regards,

Douglas Garstang  
[http://www.linkedin.com/in/garstang](http://www.linkedin.com/in/garstang)  
Email: [doug.garstang@gmail.com](mailto:doug.garstang@gmail.com)  
Cell: +1-805-340-5627
