[chef] Re: Lazy Attributes outside of resource blocks


Chronological Thread 
  • From: Lamont Granquist < >
  • To:
  • Cc: Mathew Crane < >
  • Subject: [chef] Re: Lazy Attributes outside of resource blocks
  • Date: Fri, 28 Aug 2015 16:16:07 -0700


You can force the packages to install at compile-time and then notify ohai to reload also at compile-time to pick up the changes.

Note that this may cause a bit of a race to compile_time since any prereqs (like apt-get update) will also need to move to compile-time.

It does 'fix' the platform_version problem as soon as possible in the chef run, though, which is probably what you want to do since then all the compile-time ruby code which comes later can inspect platform_version and get the 'right' answer without you having to move all your logic into ruby_blocks or lazy'ing everything -- which is likely a much worse yak shave of a converge-time arms race.

On 08/28/2015 10:56 AM, Mathew Crane wrote:
" type="cite">
Ohai chefs,

I have an interesting scenario where I need to dynamically update ohai attributes after an action is performed as part of an earlier cookbook during a chef-client run.

Scenario:
- package update runs at start of chef-client run.
- this package update in turn causes the server platform_version.to_f to jump a point release
- This platform_version attribute is used to determine a config (the release jump causes configs to change)

I've tried an ohai reload as part of the package update recipe, but both testing and documentation both indicate this won't work unless I use some sort of lazy or delayed processing to determine this attribute.

As it stands, the package update runs, chef-client completes run as if it was on the older platform_version, and then it updates the other configs 30 minutes later during the next chef-client run.

I understand that these attributes are dialed in during the compilation phase. 

My question is: how do I 'reset' the attributes within the later cookbook outside of the 'lazy' parameter in a resource block? Do I need to use some hackery within a ruby_block to reset an if/else block?

psuedo code:

variable = nil
boolean = false

if #{platform_version.to_f} >= x.y
 variable = something
 boolean = true
end

<snip>

if boolean: 
 file 'somefile'
 end
end

Thanks for any information!




Archive powered by MHonArc 2.6.16.

§