[chef] Re: Re: where is the better place for this code?


Chronological Thread 
  • From: Juan Jesús Ojeda Croissier < >
  • To:
  • Subject: [chef] Re: Re: where is the better place for this code?
  • Date: Wed, 16 Nov 2011 12:54:37 +0100

On Wed, Nov 16, 2011 at 9:19 AM, Andrea Campi
< >
 wrote:
> There are a few examples of this pattern in some providers in the base 
> Chef. The service provider for FreeBSD should be an example.
> This should probably be factored out into a common class or mixin for 
> easier reuse in custom cookbooks.
>

Yep, I think so. I could be nice to have this kind of methods
availables from cookbooks or even other parts of Chef.

Actually the check, enable and disable of Freebsd services is quite
useful to manage other conffiles.

> On Nov 16, 2011, at 12:41 AM, Juan Jesús Ojeda Croissier 
> < >
>  wrote:
[...]
>> I wrote some code for this (which is currently working), but I don't
>> know if I did in the right place and in the right way. I love to have
>> it at Chef, but I guess it need to be proven useful and the community
>> agree. By now I put it in my cookbooks at:
>> cookbooks/the_cookbook/libraries/file.rb
>>
>> Here is the actual code and example or recipe using it:
>https://gist.github.com/1368640
>>
>> But I'll write down here a simplier version:
>>
>> def include?(str)
>>  file_content = ::File.open(@path).read
>>  return true if file_content =~ /#{str}/
>>  return false
>> end
>>
>> def replace(str, str2)
>>  old_content = ::File.open(@path).read
>>  content old_content.gsub(str, str2)
>> end
>>
>> These methods are Chef::Resource::File's methods. I wrote like that
>> because was the only way I got them working, but it seems to me that
>> it should be a Providers' instead... I don't know...
>
> Looking only at your gist it's a wash, but in general yes, I would use an 
> LWRP. Keep the library, but put the "file" resource in an LWRP.
>

Sorry, but I don't get what you are saying :-/ I thing my English is
not as good as I thought. What do you mean by 'wash'?
Could you explain to me what do you mean by keep the library but
putting the 'file' resource in an LWRP? I'm a bit confuse, sorry.

Thanks a lot for your answer.

-- 
Juanje



Archive powered by MHonArc 2.6.16.

§