[chef] Re: Re: Shef for recipe writing - maybe


Chronological Thread 
  • From: Michael Glenney < >
  • To:
  • Subject: [chef] Re: Re: Shef for recipe writing - maybe
  • Date: Wed, 5 Oct 2011 10:58:41 -0700



On Tue, Oct 4, 2011 at 7:13 PM, Joshua Timberman < " target="_blank"> > wrote:
Hello!

On Tue, Oct 4, 2011 at 7:03 PM, Michael Glenney < " target="_blank"> > wrote:
>
> But what I don't know is how to test that attribute first, before committing
> that to a recipe.  Generally, for ruby scripting, I do that in IRB.  Was
> kind of hoping shef would provide that for me but I can't get it to work
> like I think it should (and/or don't understand how it should so I can
> change the way I do things).  Another case might be verifying that an
> attribute has been overridden as expected.
>
> I've tried dumping attributes from a node with 'knife node show <nodename>
> -F json > somefile.json' and then launching shef and importing those 'shef
> -j somefile.json' but I still don't seem to be able to access my attributes.

In Shef, you can enter the attributes context:

chef > attributes
chef:attributes >

I was kind of hoping for a way to "assume" the attributes already on the node but I think what you described here may actually work out better because it gives me better control and allows me to test what I want to test.  Thanks for your reply.  I'll be trying this out today.

In my trial and error I thought what I would want is "become_node".  But I haven't been able to get that to work yet.  I would start a separate thread to troubleshoot that but I don't know what I would use it for.  have you found "become_node" a useful feature in shef?  If so what type of tasks is it useful for?

And let me be the first to vote for a rename of shef.  It works well in writing but around the office we have to spell it out "Hey Bob, you should try to troubleshoot that recipe in s-h-e-f", "Does anyone have experience with this s-h-e-f tool?", etc.  How about "chirb"?  Or, keeping with the theme, "crockpot"?  "wok"?  ;)


Which lets you apply attributes to the node object as though you were
modifying a cookbook's attributes file.

If you want to operate on the node object as though in the context of a recipe:

chef > recipe

Then use the set, default or override methods on the node object to
set the attributes you want for testing purposes.

chef > recipe
chef:recipe > node.set['tomcat']['folder'] = "/usr/local/tomcat"

To 'erase' the attribute value (e.g., test for non-extistence, simply
set it to nil.

> I'm not really seeking tech support here.  More I'd like to hear from the
> people who are knee deep in chef every day.  Is shef the IRB of Chef as I
> assumed it was?  Do you know of any "best practices" guides or how-tos for
> writing recipes and the best tools/environment settings for doing so?  Am I
> completely off in left field (aka, I'm looking at this all wrong)?

Yes. Shef is an IRB console with a bunch of Chef classes already
loaded. It can function in different contexts (attributes, recipe,
main) and modes (solo, client, standalone). I probably use Shef daily
in testing recipe development.

The wiki has:

http://wiki.opscode.com/display/chef/Shef

We're working on adding a unit on Shef to the Chef Advanced training class.


MG




Archive powered by MHonArc 2.6.16.

§