[chef] Re: Re: Re: Re: Re: accessing environment attributes in cookbooks


Chronological Thread 
  • From: Jesse Campbell < >
  • To: chef < >
  • Subject: [chef] Re: Re: Re: Re: Re: accessing environment attributes in cookbooks
  • Date: Wed, 26 Dec 2012 14:43:05 -0500

to be able to specify something like "#{node[: my_attr]}/some/directory" in an attribute file, you'll have to wait for chef 11.

you can do the same thing in your recipe until then:
node.default['my_cookbook']['cookbook_dir'] = "#{node[:
 my_attr]}/some/directory"




On Wed, Dec 26, 2012 at 2:16 PM, Steven Lehrburger < " target="_blank"> > wrote:
Mike and Daniel, thanks for the responses, and that makes sense about the attributes files. I did try logging from my cookbook's recipes/default.rb file, but my environment attribute was being evaluated as an empty string.

For example, with this in my environment's JSON file:

"default_attributes": {
  "my_attr": "/my/path"
},

Then if I put this in my attributes/default.rb file:

default['my_cookbook']['cookbook_dir'] = "#{node[: my_attr]}/some/directory"

And then log it like this in my recipes/default.rb:

Chef::Log.info(node[:my_attr])
Chef::Log.info(node['my_cookbook']['cookbook_dir'])

Then it logs:

INFO: /my/path
INFO: /some/directory

And not:

INFO: /my/path
INFO: /my/path/some/directory

Which is what I want. I would guess I'm just not using the proper syntax to define my attribute? But I've tried it with everything I can think of, and it's fine if I have to explicitly load the environment until Chef 11 :)

Thanks!

/~s


On Wed, Dec 26, 2012 at 11:09 AM, Mike < " target="_blank"> > wrote:
Ok, what he said. :)

On Wed, Dec 26, 2012 at 11:07 AM, Daniel DeLeo < " target="_blank"> > wrote:
>
> On Wednesday, December 26, 2012 at 8:00 AM, Mike wrote:
>
> Hi Steven,
>
> You've placed your debugging code in the attributes/default.rb file,
> this gets evaluated at compile time.
>
> Have you tried placing the same debugging code in the
> recipes/default.rb (or somewhere like that) where the debugging
> statement will show what the value of an attribute is at the execution
> phase?
>
> -Mike
>
> A slightly longer explanation:
>
> Attributes from roles and environments are not applied to the node until
> after attributes files have all been evaluated. In Chef 11, this has been
> changed and you will be able to use role/environment attributes in
> attributes files.
>
>
> --
> Daniel DeLeo
>





Archive powered by MHonArc 2.6.16.

§