Overriding cookbook attributes in a role - am I doing it wrong?


#1

I have an attribute default set in a cookbook attributes file:

default[:lmds][:database][:host] = “localhost”

which I’m attempting to override in a role:

$ knife role show lmds-app -a default_attributes
{
“default_attributes”: {
“lmds”: {
“database”: {
“host”: “i-3F2007E9”
}
}
}
}

I then apply that role to a node:

$ knife node show -r i-3DBB07DC.ec.int.realestate.com.au
{
“run_list”: [
“role[lmds-app]”
]
}

However, the node is picking up the cookbook-default, “localhost”, rather than the value specified in the role. Based on the documentation on the Chef Wiki, I thought the role would trump the cookbook. Am I doing the override incorrectly?

If I put the override in node attributes, rather than the role, then it works … but I don’t want to have to do that for every node.


cheers,
Mike Williams


#2

On 23/11/2010, at 18:47 , Mike Williams wrote:

However, the node is picking up the cookbook-default, “localhost”, rather than the value specified in the role. Based on the documentation on the Chef Wiki, I thought the role would trump the cookbook. Am I doing the override incorrectly?

Sorry, should have said: Chef version 0.912.


cheers,
Mike Williams


#3

On Nov 22, 2010, at 11:48 PM, Mike Williams wrote:

On 23/11/2010, at 18:47 , Mike Williams wrote:

However, the node is picking up the cookbook-default, “localhost”,
rather than the value specified in the role. Based on the
documentation on the Chef Wiki, I thought the role would trump the
cookbook. Am I doing the override incorrectly?

Sorry, should have said: Chef version 0.912.

Shouldn’t that be override_attributes, not default_attributes?

–Noah


#4

On Tue, Nov 23, 2010 at 2:47 AM, Mike Williams
mike@cogentconsulting.com.au wrote:

I have an attribute default set in a cookbook attributes file:
which I’m attempting to override in a role:
I then apply that role to a node:

A node doesn’t get its attributes updated until chef-client runs on
that node. Did that happen between the role change and the “knife
node show?”

On Tue, Nov 23, 2010 at 11:36 AM, Noah Kantrowitz noah@coderanger.net wrote:

Shouldn’t that be override_attributes, not default_attributes?

Depending on the ultimate goal, an override may make more sense, but
either works in this case: role “defaults” override attributes file
"defaults"; see the precedence chart here:

http://wiki.opscode.com/display/chef/Attributes#Attributes-SettingAttributes


Mark J. Reed markjreed@gmail.com


#5

On 24/11/2010, at 03:45 , Mark J. Reed wrote:

On Tue, Nov 23, 2010 at 2:47 AM, Mike Williams
mike@cogentconsulting.com.au wrote:

I have an attribute default set in a cookbook attributes file:
which I’m attempting to override in a role:
I then apply that role to a node:

A node doesn’t get its attributes updated until chef-client runs on
that node. Did that happen between the role change and the “knife
node show?”

Yes, I ran chef-client after the role change.

Do the node attributes actually get “updated”, ie. persisted? I assumed that the role attributes and cookbook attributes would just be merged with the node attributes at chef-client runtime.


cheers,
Mike Williams


#6

On Tue, Nov 23, 2010 at 3:10 PM, Mike Williams
mike@cogentconsulting.com.au wrote:

Do the node attributes actually get “updated”, ie. persisted? I assumed that the role attributes and cookbook attributes would just be merged with the node attributes at chef-client runtime.

That depends on the type of node, and that’s a good point. Default
values are computed at runtime and, since 0.9.0, not persisted - which
means they won’t show up in “knife node show”. So you’d have to have
a recipe running on the node output the values (or examine the node
object interactively in shef) to see the computed values.


Mark J. Reed markjreed@gmail.com


#7

On Tue, Nov 23, 2010 at 3:33 PM, Mark J. Reed markjreed@gmail.com wrote:

On Tue, Nov 23, 2010 at 3:10 PM, Mike Williams
mike@cogentconsulting.com.au wrote:

Do the node attributes actually get “updated”, ie. persisted? I assumed that the role attributes and cookbook attributes would just be merged with the node attributes at chef-client runtime.

That depends on the type of node, and that’s a good point.

Er, I mean, depends on the type of attribute. It’s the default
attribute values which aren’t persisted.


Mark J. Reed markjreed@gmail.com


#8

On 24/11/2010, at 07:33 , Mark J. Reed wrote:

Default
values are computed at runtime and, since 0.9.0, not persisted - which
means they won’t show up in “knife node show”. So you’d have to have
a recipe running on the node output the values (or examine the node
object interactively in shef) to see the computed values.

How do I inspect the computed values using shef?


cheers,
Mike Williams