[chef] Re: attributes constructed from other attributes aren't added to the attribute map


Chronological Thread 
  • From: AJ Christensen < >
  • To: " " < >
  • Subject: [chef] Re: attributes constructed from other attributes aren't added to the attribute map
  • Date: Tue, 23 Dec 2014 08:19:22 +1300

The syntax is not wrong, this is unfortunately a very rare edge case
with the way that attribute reads are evaluated.

You can move any computed attributes to the Recipe's Compile Phase in
order to Not Be Bitten By Things., e.g.:

``` ruby
node.default['chef_attribute_hell']['attr2'] = "#{...}/..."
node.default['chef_attribute_hell']['attr3'] =
"#{node.chef_attribute_hell.attr2}/attr3"
```

I wish the notes from the "Attributes WAT" community session had been
captured but it was a very high energy discussion -- we went into the
details as to what causes this to occur. Something to do with the
"read time" of the attributes in the attributes DSL being before some
attribute precedence resolution happens, I fear, although I don't
recall. HTH.

cheers,

--aj

On Tue, Dec 23, 2014 at 7:38 AM, Stefán Freyr Stefánsson
< >
 wrote:
> Hi.
>
> I just started using test-kitchen again after a bit of a break. I was
> surprised to find out that a very simple internal cookbook that we've been
> using now didn't work.
>
> The error occurred when evaluating our default attribute file. It was
> complaining about an attribute (attr3) that was composed with the value of
> another attribute (attr2), which in turn was composed from the value of
> another attribute (attr1). After adding some "raise" lines to the default.rb
> attribute file in our cookbook and a test recipe we were able to determine
> that attr1 was added to the map, while attr2 was not added and trying to
> construct attr3 then resulted in a failure.
>
> Sorry for the convoluted explanation, I make some sad attempt to describe
> this here: https://gist.github.com/StFS/2a333afe352d0dc8cbb5
>
> As I said I was using test-kitchen for this and in my .kitchen.yml file I
> had:
>   require_chef_omnibus: true
>
> This installed Chef 12.0.3-1 on the vagrant machine (which is a CentOS 7).
> Since this had been working previously I dug around a bit and noticed that
> all of our earlier installations seemed to be using version 11 of Chef. So I
> changed my .kitchen.yml file to specify version 11 of chef and now at least
> I'm getting further and the attributes map seems to be built correctly in my
> recipe.
>
> So my question is, is the following syntax for my attribute file in some way
> wrong? If so, what should I be using? If the syntax is not wrong, is this
> then a bug in Chef 12? Has it been reported (I didn't find anything during
> my googling around for this problem)?
>
> Here is an example of an attribute file that would fail:
>
> default['chef_attribute_hell']['attr1'] = "attribute1"
> default['chef_attribute_hell']['attr2'] =
> "#{node.chef_attribute_hell.attr1}/attr2"
> default['chef_attribute_hell']['attr3'] =
> "#{node.chef_attribute_hell.attr2}/attr3"
>
> Kind regards,
> Stefan Freyr
>
> p.s. I can make a full blown cookbook with a .kitchen.yml file available
> which demonstrates this problem if needed.



Archive powered by MHonArc 2.6.16.

§