0
votes

I read in Chef site that for default attributes specified in environment takes higher precedence than default attributes specified in roles. This makes sense as we may have different web-server for development, testing and production.

But in case of override attribute this is reverse i.e override attributes of roles takes precedence over override attribute of roles. I am not able to guess reason behind this ? Can anyone please explain me why chef chose such precedence ordering.

I am also adding complete list of attribute precedence as given in chef site

  • The default attribute specified in a cookbook attribute file.
  • The default attribute specified in a recipe.
  • The default attribute specified in an environment.
  • The default attribute specified in a role.
  • The force_default attribute specified in aa cookbook attribute file.
  • The force_default attribute specified in a recipe.
  • The normal attribute specified in a cookbook attribute file.
  • The normal attribute specified in a recipe.
  • The override attribute specified in a cookbook attribute file.
  • The override attribute specified in a recipe.
  • The override attribute specified in a role.
  • The override attribute specified in an environment.
  • The force_override attribute specified in a cookbook attribute file.
  • The force_override attribute specified in a recipe.
  • The automatic attribute collected during the Ohai run.

Thanks

1
This is not the right place to ask "why?" questions like this. You are welcome to jump on IRC and ask there though. - coderanger
It's the other way around. The default attributes set on a role take higher precedence over the ones set on the environment -- i.e. if you set the same default on both the role and the environment, the one on the role wins. The opposite is true for override attributes. If you override an attribute on the environment, it will win over the overrides set elsewhere, including on roles. - cassianoleal

1 Answers

0
votes

The explanation for the override order is on the site you link to. Just be clear though, because it's a common confusion, precedence in that documentation is referring to the order in which values are fed to the evaluation sequence. Because the evaluation is in a overwrite form, the lowest precedence values are the ones that you get after evaluation is complete. Thus there is no way to override Ohai supplied values.

The attribute precedence order for roles and environments is reversed for default and override attributes. The precedence order for default attributes is environment, then role. The precedence order for override attributes is role, then environment. Applying environment override attributes after role override attributes allows the same role to be used across multiple environments, yet ensuring that values can be set that are specific to each environment (when required). For example, the role for an application server may exist in all environments, yet one environment may use a database server that is different from other environments.

As to the why of the default doesn't use the same logic as override, I don't know.