Introducing Chef Sugar!

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

Sweeeeeeet! :slight_smile:
On Oct 15, 2013 7:51 AM, "Seth Vargo" sethvargo@opscode.com 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-494https://tickets.opscode.com/browse/COOK-494.
I whipped up a small solution called Chef Sugarhttps://github.com/sethvargo/chef-sugar
(GitHub - sethvargo/chef-sugar) and published a Gemhttps://rubygems.org/gems/chef-sugar
and Cookbook https://community.opscode.com/cookbooks/chef-sugar.

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 methodshttps://github.com/sethvargo/chef-sugar/blob/master/lib/chef/sugar/platform.rb#L22-L73
.

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 YARDhttp://rubydoc.info/github/sethvargo/chef-sugar/master/frames 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 https://twitter.com/sethvargo

Nice, this looks awesome !

Seth Vargo mailto:sethvargo@opscode.com
October 15, 2013 at 1:51 AM

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
https://tickets.opscode.com/browse/COOK-494. I whipped up a small
solution called Chef Sugar
https://github.com/sethvargo/chef-sugar (GitHub - sethvargo/chef-sugar)
and published a Gem https://rubygems.org/gems/chef-sugar and
Cookbook https://community.opscode.com/cookbooks/chef-sugar.

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
https://github.com/sethvargo/chef-sugar/blob/master/lib/chef/sugar/platform.rb#L22-L73.

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
http://rubydoc.info/github/sethvargo/chef-sugar/master/frames 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 https://twitter.com/sethvargo