[chef] RE: Re: Using standard ruby modules in LWRP


Chronological Thread 
  • From: Paul Choi < >
  • To: " " < >
  • Subject: [chef] RE: Re: Using standard ruby modules in LWRP
  • Date: Tue, 9 Nov 2010 18:58:01 +0000
  • Accept-language: en-US

Great, thanks!

I do remember seeing that somewhere while trying to learn Ruby.

Maybe I can add this to the wiki to warn those who aren’t so proficient in Ruby. J

 

-Paul

 

From: Alex Soto [mailto:
Sent: Tuesday, November 09, 2010 10:52 AM
To:
Subject: [chef] Re: Using standard ruby modules in LWRP

 

prepend '::' to qualify the namespace

 

example:

 ::File.directory?

 

On Nov 9, 2010, at 10:41 AM, Paul Choi wrote:



Hello,

 

Maybe someone can tell me if there’s a better way to do this.

 

I wrote an LWRP that, given a user account, creates the user account, gid, directory, creates user’s authorized_keys. And I often like to use File.directory? or File.exist? and others in my recipes.

 

If I call File.directory? in a provider, however, Chef interprets it as Chef::Providers::File:Class (or something like that).

 

So a silly workaround I did was to create libraries/file.rb, and in it:

Class Chef

  Class Recipe

    Class Plaxo

      Require ‘ftools’

   end

  end

end

 

Then I can call Chef::Recipe::Plaxo::File.directory? and whatnot.

 

Is there a more elegant way of doing this? J

 

For those who are not familiar with LWRP, I encourage you to check it out. It’s a bit of work to understand and set it, but it allows me to do stuff like:

  plaxo_user “opsman” do

    action :set

  end

Which fetches user info from data bags, creates group, user, sets up user’s authorized_keys, etc. Pretty cool, stuff, this LWRP.

 

-Paul

 

 




Archive powered by MHonArc 2.6.16.

§