- From: Juan Jesús Ojeda Croissier <
>
- To:
- Subject: [chef] Re: Re: Re: Re: How to add ruby lib as depend at LWRP
- Date: Tue, 13 Dec 2011 16:45:03 +0100
Hi :-)
Acctually, I did try that before the last solution I put before, but I
got this message:
FATAL: NameError: undefined local variable or method `node' for
#<Class:0xb6c506b4>
So I used @node instead of node:
run_context = Chef::RunContext.new(@node, {})
f = Chef::Resource::AptPackage.new("libsqlite3-ruby", run_context)
f.run_action(:install)
And I got this:
FATAL: NoMethodError: undefined method `cookbook_collection=' for nil:NilClass
I'll keep looking on this.
Thanks for the feedback.
On Tue, Dec 13, 2011 at 4:12 PM, Thom May
<
>
wrote:
>
Hey
>
plain ruby code is executed at Compile time, not at converge time, so
>
the timing is right. That said, I've only done similar in a recipe
>
context, but i think the following code should do what you need:
>
>
run_context = Chef::RunContext.new(node, {})
>
p = Chef::Resource::AptPackage.new("libsqlite3-ruby", run_context)
>
p.run_action(:install)
>
>
-T
>
>
2011/12/13 Juan Jesús Ojeda Croissier
>
<
>:
>
> On Tue, Dec 13, 2011 at 1:08 PM, Bryan Berry
>
> <
>
>
> wrote:
>
>> juanje
>
>>
>
>> how about this?
>
>>
>
>> # at beginning of lwrp
>
>> f = package "foo" do
>
>> action :install
>
>> end
>
>> f.run_action(:install)
>
>>
>
>> this might trigger the install action immediately
>
>>
>
>> this is just an idea. I have done something similar w/ execute resources
>
>> but
>
>> not with package resources
>
>>
>
>
>
> Like that, doesn't work, but I think is good start. After some tries I got:
>
>
>
> f = Chef::Resource::AptPackage.new "libsqlite3-ruby" do
>
> action :install
>
> end
>
> f.run_action(:install)
>
>
>
> But it ask me for the run_context:
>
>
>
> FATAL: ArgumentError: apt_package[libsqlite3-ruby] (dynamically
>
> defined) had an error: Cannot find the provider for a resource with no
>
> run context set
>
>
>
> I tried this:
>
> f = Chef::Resource::AptPackage.new("libsqlite3-ruby",
>
> Chef::RunContext.new(@node,
>
> Chef::CookbookCollection.new(Chef::CookbookLoader.new(Chef::Config[:cookbook_path]))))
>
> f.run_action(:install)
>
>
>
> Still no luck:
>
> NoMethodError: undefined method `cookbook_collection=' for nil:NilClass
>
>
>
> But getting close. I think...
>
>
>
> Thanks for the help :-)
>
>
>
>> 2011/12/13 Juan Jesús Ojeda Croissier
>
>> <
>
>
>>>
>
>>> Hi :-)
>
>>>
>
>>> I was tring to find a example or doc about how to do it and I didn't
>
>>> find. Maybe I didn't know where to search...
>
>>>
>
>>> My problem is that I have a LWRP that need a Ruby library ( require
>
>>> 'sqlite3' ) and I don't know how to be sure that the library is
>
>>> already installed.
>
>>> Is there any way to install the package from the cookbook before the
>
>>> provider (LWRP) be loaded?
>
>>>
>
>>> Any pointers will help. I'm already trying at
>
>>> $COOKBOOK/libraries/default.rb with no much luck. At least I don't
>
>>> know how to call properly from there the 'package' provider.
>
>>>
>
>>> Thanks :-)
>
>>>
>
>>> --
>
>>> Juanje
>
>>
>
>>
>
>
>
>
>
>
>
> --
>
> Juanje
--
Juanje
Archive powered by MHonArc 2.6.16.