[chef] Re: Introducing Chef Sugar!


Chronological Thread 
  • From: Torben Knerr < >
  • To:
  • Subject: [chef] Re: Introducing Chef Sugar!
  • Date: Tue, 15 Oct 2013 18:17:53 +0200

Sweeeeeeet! :-)

On Oct 15, 2013 7:51 AM, "Seth Vargo" < "> > wrote:

Ohai!

(I apologize if you received multiple copies of this email. My email client just had a small seizure...)

Tonight I was browsing tickets and came across COOK-494. I whipped up a small solution called Chef Sugar (https://github.com/sethvargo/chef-sugar) and published a Gem and Cookbook

I could really use some help testing this out, especially on Windows. The cookbook is fairly simple - it just installs the gem as a chef_gem and requires the library. 

The Gem itself (also located at the above repository) has two "modes" - DSL and Library. In DSL mode, the node object is implicit:

# recipes, resources, and providers
do_something if windows?

In Library mode, the node object is required as the first argument:

do_something if Chef::Sugar::PlatformFamily.windows?(@node)

You can also use the module as a pure Mixin:

require 'chef/sugar/platform_family'
include Chef::Sugar::PlatformFamily

do_something if windows?(@node)

The coolest part is the dynamically-mapped platform names to versioned releasese, such as ubuntu_before_precise? and mac_os_x_after_or_at_mountain_lion?. These methods are dynamically built in a really cool way. If you're interested, take a look at the source code for dynamically building these methods.

Many of the methods in the gem are just wrappers around checking node attributes, but there is a very helpful shell module:

log "Using mongo at '#{which 'mongo'}' with version '#{version_for 'mongo'}'"

# Replace pesky 'which command && command --version == 1.2.3'
execute 'install[thing]' do
  command '...'
  not_if  { installed_at_version?('command', '1.2.3') }
end

There's a little bit of magic under the hood, but all of the code is documented with YARD and should be pretty straight forward.

Let me know what you think. Feel free to reply to this thread of shoot me an email directly.

If there's a feature/check/helper method you think would be beneficial, open up an Issue on GitHub or send a Pull Request :).

Happy Cook(book)ing,
Seth Vargo
Solutions Engineer, Opscode
@sethvargo




Archive powered by MHonArc 2.6.16.

§