[chef] Re: Using standard ruby modules in LWRP


Chronological Thread 
  • From: Alex Soto < >
  • To:
  • Subject: [chef] Re: Using standard ruby modules in LWRP
  • Date: Tue, 9 Nov 2010 10:51:27 -0800
  • Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:mime-version:content-type:subject:date:in-reply-to:to :references:message-id:x-mailer; b=PLRbkPHz56QXDXOfQGptqnEQW9LumP68xvUiZrexde1/IR7xOFAa3v9Yk1trjx10zP JO9/ZnAZbFLGXjCeAguD48UgimurFyM8DqALHTBaQF1POQEZvVKERyE2SeGHkDO5OYJ/ 68PZ+Hi20PEnsZv9/JzwDk5nEA8TlBuR2V68Y=

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.

§