[chef] Using standard ruby modules in LWRP


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

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.

§