Confused about environments


#1

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


#2

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
2407 S Congress Ave Ste E-350
Austin, TX 78704
United States

From: Douglas Garstang doug.garstang@gmail.com
To: 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


#3

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. :frowning: 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.comwrote:

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
Email: doug.garstang@gmail.com
Cell: +1-805-340-5627


#4

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-repohttp://docs.opscode.com/essentials_repository.htmland 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.comwrote:

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. :frowning: 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

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
Email: doug.garstang@gmail.com
Cell: +1-805-340-5627


#5

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 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-repohttp://docs.opscode.com/essentials_repository.htmland 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

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. :frowning: 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> 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
Email: doug.garstang@gmail.com
Cell: +1-805-340-5627


Regards,

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


#6

You’re usually the one talking about (or bitching about) corner cases in
#chef. 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
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.comwrote:

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-repohttp://docs.opscode.com/essentials_repository.htmland 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

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. :frowning: 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

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
Email: doug.garstang@gmail.com
Cell: +1-805-340-5627


Regards,

Douglas 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


#7

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.comwrote:

You’re usually the one talking about (or bitching about) corner cases in
#chef. 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
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.comwrote:

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-repohttp://docs.opscode.com/essentials_repository.htmland 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> 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. :frowning: 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> 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
Email: doug.garstang@gmail.com
Cell: +1-805-340-5627


Regards,

Douglas 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


Regards,

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


#8

On Fri, Feb 14, 2014 at 7:17 PM, Douglas Garstang
doug.garstang@gmail.comwrote:

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):


#9

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
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

wrote:

You’re usually the one talking about (or bitching about) corner cases in
#chef. 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
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.comwrote:

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-repohttp://docs.opscode.com/essentials_repository.htmland 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

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. :frowning: 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

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


#10

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


Larry Wright
@larrywright

On February 14, 2014 at 3:41:09 PM, Douglas Garstang (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


#11

On Feb 14, 2014, at 8:18 PM, Morgan Blackthorne 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
LinkedIn Profile: http://tinyurl.com/y8kpxu


#12

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 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


Larry Wright
@larrywright http://twitter.com/larrywright

On February 14, 2014 at 3:41:09 PM, Douglas Garstang (
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
Email: doug.garstang@gmail.com
Cell: +1-805-340-5627