- From: Rajiv Ranganath <
>
- To:
- Subject: [chef] Re: Re: Re: Accessing Node Object in Libraries
- Date: Fri, 16 May 2014 12:26:16 -0700
On Fri, May 16, 2014 at 10:31 AM, Daniel DeLeo
<
>
wrote:
>
On Friday, May 16, 2014 at 7:34 AM, Julian C. Dunn wrote:
>
>
> "Should you": that's an architectural question for our developers,
>
> presumably. You're right -- I usually pass either the node object
>
> itself or the attributes thereof to a helper, if I need them:
>
>
[...]
>
The difference with library files is that they’re 100% plain ruby,
>
evaluated in the context of the top level ruby environment (the
>
TOPLEVEL_BINDING object) so there is no architecturally sound way for
>
Chef to hook into them and add additional context (e.g., access to
>
the node object). By comparison, other file types, such as recipes,
>
attributes, and LWRPs, are evaluated in the context of an object that
>
chef initializes for you, so chef can internally set variables (node,
>
run_context, etc.) before handing control over to your code.
This behavior allows for some very interesting things we can do to Chef
from cookbooks.
https://github.com/lambda-linux-cookbooks/chef-solo-node-save/blob/master/libraries/node_ext.rb
Please be careful if you are trying this at home! :-)
Best,
Rajiv
Archive powered by MHonArc 2.6.16.