[chef] Re: Wrapper cookbooks, templates, lazy


Chronological Thread 
  • From: Noah Kantrowitz < >
  • To:
  • Subject: [chef] Re: Wrapper cookbooks, templates, lazy
  • Date: Thu, 16 Oct 2014 11:11:45 -0700


On Oct 16, 2014, at 10:49 AM, Justin Dossey 
< >
 wrote:

> I ran into an interesting one today.
> 
> If you're wrapping a (community) cookbook and your wrapper needs lazy {} to 
> move evaluation of something to the execute phase, the #resources method 
> doesn't work.
> 
> Example
> 
> Cookbook foo, recipes/default.rb
> 
> file '/tmp/foo.txt' do
>    owner node['foo']['user']
> end
> 
> Cookbook bar, recipes/default.rb
> include_recipe 'foo::default'
> 
> user 'new_user'
> node.override['foo']['user'] = 'new_user'
> 
> # this doesn't work:
> resources(file: '/tmp/foo.txt').owner( lazy { node['foo']['user'] })

Use this:

resources(file: '/tmp/foo.txt').owner(Chef::DelayedEvaluator.new { 
node['foo']['user'] })

#lazy is just a helper method for that, but only available in the resource 
class scope.

--Noah

Attachment: signature.asc
Description: Message signed with OpenPGP using GPGMail




Archive powered by MHonArc 2.6.16.

§