- From: Juan Jesús Ojeda Croissier <
>
- To:
- Subject: [chef] Re: Re: Re: Re: Re: Re: How to add ruby lib as depend at LWRP
- Date: Wed, 14 Dec 2011 00:26:09 +0100
Hi :-)
On Tue, Dec 13, 2011 at 6:16 PM, Zac Stevens
<
>
wrote:
>
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 -->
>
Nice! Good idea :-)
>
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.
>
You were right, I made the changes you suggest and it's working fine so far
:-)
https://gist.github.com/1474442
Thanks a lot!
--
Juanje
- [chef] Re: Re: How to add ruby lib as depend at LWRP, (continued)
Archive powered by MHonArc 2.6.16.