[chef] Re: Re: Nested node attributes not working as expected when using overrides?


Chronological Thread 
  • From: Torben Knerr < >
  • To:
  • Subject: [chef] Re: Re: Nested node attributes not working as expected when using overrides?
  • Date: Fri, 19 Oct 2012 16:53:44 +0200

Waah, really? I hoped I did something wrong. Wouldn't that violate the principle of least surprise? Or is it just me who is "surprised" by that... 

Btw: I'm seeing this pattern in lots of recipes, guess this would be a surprise to some of the authors as well.

Is this documented anywhere in the Wiki?


On Fri, Oct 19, 2012 at 4:47 PM, Bryan Baugher < " target="_blank"> > wrote:
Yes I believe this is expected. I ran across this problem and the solution is that if you ever use nested attributes, you should always use them in your recipes and not in attributes as Chef cannot guarantee the ordering of when things are loaded (i.e. environments, attributes files, roles...)


On Fri, Oct 19, 2012 at 9:43 AM, Torben Knerr < " target="_blank"> > wrote:
Hi Chefs!

I'm often using something like this in my attributes/default.rb:

    default['my_recipe']['base_dir']  = '/path/to/basedir'
    default['my_recipe']['other_dir']  = "#{node['my_recipe']['base_dir']}/otherdir"

This looks sane at first, but as soon as I'm overriding the default value for ['my_recipe']['base_dir'], e.g.  in a role like so...

    ...
    default_attributes({
      :my_recipe => {
        :base_dir => '/somewhere/else'
      }
    })
    ...

...I get a weird behavior when using the node attributes in my recipe:

=> node['my_recipe']['base_dir'] renders to '/somewhere/else'
=> node['my_recipe']['other_dir'] renders to '/path/to/basedir/otherdir'

Is this the expected behaviour?!

Cheers,
Torben

P.S.: this was under omnibus chef 10.14.4 on a 64 bit Ubuntu 12.04



--
-Bryan




Archive powered by MHonArc 2.6.16.

§