Skip to content

Instantly share code, notes, and snippets.

@jnwng
Last active December 15, 2015 20:19
Show Gist options
  • Save jnwng/5317609 to your computer and use it in GitHub Desktop.
Save jnwng/5317609 to your computer and use it in GitHub Desktop.
Substitute file dashes for slashes (like they should be to override node attributes)
if default['postgresql']['version'] == "9.1"
default['postgresql']['main_dir'] = "foo"
else
default['postgresql']['main_dir'] = "bar"
normal['postgresql']['version'] = "9.1"
default['postgresql']['version'] = "9.2"
default['postgresql']['dir'] = "/etc/postgresql/#{node['postgresql']['version']}/main"
@jnwng
Copy link
Author

jnwng commented Apr 5, 2013

Imagine the situation as such:my_cookbook has a dependency on postgresql cookbook. I override the postgresql cookbook version with 9.1, and only that attribute. However, my_cookbook depends on postgresql cookbook, meaning it gets loaded before my cookbook (via Chef 11). Therefore, postgresql attributes get evaluated before mine, and although I have a better attribute precedence via normal, the second postgresql attribute depends on the first, and is now out of date when my_cookbook attributes are evaluated for the node.

@jnwng
Copy link
Author

jnwng commented Apr 5, 2013

I could be very wrong if the default['postgresql']['dir'] attribute doesn't get actually evaluated until use, however based on the last couple of days that I've dealt with this, it looks like the attributes that depend on this being here don't get updated (which makes sense given how its coded). Roles would work, as well as environments, but previously, before Chef 11, it worked pretty well to just override inside this cookbook.

It is also the case that if the second attribute is nested inside of an attribute test, that it would remain out-of-date when it gets evaluated (see third Gist).

@jnwng
Copy link
Author

jnwng commented Apr 5, 2013

Not particularly sure what the best method is of overriding these attributes, but presumably its too much to ask to understand what node attribute depend on other attributes. However, might be the case that people need to document these attribute dependencies, or otherwise specify these attributes in environments as opposed to in their cookbooks (although cookbooks make the most sense).

@jnwng
Copy link
Author

jnwng commented Apr 5, 2013

Some context, using chef-solo and chef 11. Just trying to hopefully clarify some of the attribute changes that were made

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment