Weird attributes issue


#1

Hi,
I am dealing with a weird attributes issue. In my attributes/default.rb file, I have the following:

default[:test][:version] = ‘1.2.3’

I ran my recipe and used this attribute. Later I changed the value of attribute in default.rb file
to ‘2.3.4’. I expected my recipe to see the new value. However, its still seeing old value. Seems like the old value is being cached some where. I am not over writing this value any where else. Only referencing it. Even if I comment out that line in default.rb, my recipe still sees the old value.

I changed the line in attributes/default.rb as follows:

node.set[:test][:version] = value

Now my recipe sees what ever value is in the default.rb file. If I change default.rb to the way it was earlier i.e. changed the ‘node.set’ to ‘default’. It still retains the old value set using node.set.

I enabled attributes debugging by adding the following code to my recipe:

require 'pp’
pp node.debug_value(:test, :version)

I see the following:

Compiling Cookbooks...
[["set_unless_enabled?", false],
 ["default", "6.5.1"],
 ["env_default", :not_present],
 ["role_default", :not_present],
 ["force_default", :not_present],
 ["normal", "6.4.1"],          <--- this is the old value that my recipe sees
 ["override", :not_present],
 ["role_override", :not_present],
 ["env_override", :not_present],
 ["force_override", :not_present],
 ["automatic", :not_present]]

How do I ensure, that my recipe always gets the value in my attributes file and not some cached value? Thanks.


#2

node.set creates an attribute with ‘normal’ priority. The special thing about normal priority attributes is that they are persisted across runs. Because they are higher priority than ‘default’, you see the old normal value, rather than the new default value. You will need to delete the normal attribute value (e.g. knife node edit, or node.rm(:test, :version) programmatically), then it will pick up your default attribute.


#3

Thanks Christine,
That certainly explains what I am observing. Is there a way to disable persistence of node attributes and have them always pick them up from attributes file. I’d like to see consistent behavior based on what’s in the attributes file. Thanks.


#4

The behavior’s not configurable. Best advice I can give is avoid using normal attributes unless you need the persistence. Don’t use node.set, use node.default or node.override. The other priorities behave as you would expect.