Muradin007
Muradin007

Reputation: 158

Chef node vs environment

I am a bit lost on trying to figure out the difference between node and environment on this setup that I have come to be managing. I'm not sure if there's something I'm missing, if this is bad practice, or what have you. I'm also new to chef, and slowly gaining knowledge of it.

I understand the node as the machine that is running a chef-client and maintaining desired state according to a run-list.

I also understand that an environment is used to describe information about a particular environment, and will have variables likely specific to that environment.

What I see in the chef-repo and the code I am managing though, is very much similar --- if not completely overlapping.

Given a node registered with the chef-server, and an environment specified to run against -- I see the same configurations.

On the node, there's information about which cookbook versions to use, which environment chef_environment is set to, and specific application variables only relevant to that application, machine collected hardware stats, and even more.

On the environment, there is the same collection of information, cookbook versions, app variables and settings.

I don't even think the environment mentioned in the node is respected, given that a different environment is specified on the command run by a knife bootstrap on bamboo.

My question is this --- is this redundant? Which settings are honored, and which are ignored, can this be cut down and made simpler? Is this a common and correct setup?

Upvotes: 0

Views: 847

Answers (1)

minamijoyo
minamijoyo

Reputation: 3445

In general, you should define node attributes only for unique information such as host name which is different for each server.

When setting the same attribute in the node and environment, the priority is a bit complicated. Chef's attribute has six levels of overwriting:

  • default
  • force_default
  • normal
  • override
  • force_override
  • automatic

At the same level, the environment takes precedence over node, which may be contrary to intuition. You can adjust the priority of overwriting by using different levels such as default and override.

For details, refer to the table of the following document: https://docs.chef.io/attributes.html#attribute-precedence

Upvotes: 0

Related Questions