[chef] Re: Re: Re: Re: Re: How to add ruby lib as depend at LWRP


Chronological Thread 
  • From: Zac Stevens < >
  • To:
  • Subject: [chef] Re: Re: Re: Re: Re: How to add ruby lib as depend at LWRP
  • Date: Tue, 13 Dec 2011 17:16:59 +0000

Hi Juan,

2011/12/13 Juan Jesús Ojeda Croissier 
< >:
> I know it shouldn't be so complicated, but the the Bryan's solution
> doesn't work like that, because I need the library installed at the
> node for the provider. I mean, before my provider (LWRP) is loaded.
>
> The 'require' is at the provider, so use the package resource from the
> recipe doesn't help at all. The compile fails before the recipe is
> even loaded.
>
> Here is the original I trying to fix:
> https://github.com/gecos-team/cookbook-bookmarks/blob/master/providers/bookmarks.rb

Okay, I understand now.  I'm solving this (in a library, but it should
also work for an LWRP) by requiring the gem like so:

begin
  require 'mygem'
rescue LoadError => e
  Chef::Log.warn("Dependency 'gem' not loaded: #{e}")
end
<-- rest of the library code goes here -->

This prevents Chef from failing when the library can't require the
gem, but the library code is still loaded.  The recipe code then has:

package 'rubygem-mygem' do
  action :nothing
end.run_action(:install)
Gem.clear_paths
require 'mygem'

This runs at compile time, and ensures that 'mygem' has been loaded
before the converge stage.  So long as the library code is only used
during the converge stage, that works fine.

I believe the same should be true for your LWRP - you will only have
problems if you're invoking your LWRP actions at compile-time, using
the run_action() approach used here to install the gem.
Unfortunately, I don't have an example of this in an LWRP myself, so
I'm not _certain_ that it will work for you.


Zac



Archive powered by MHonArc 2.6.16.

§