Adoptable Cookbooks List

Looking for a cookbook to adopt? You can now see a list of cookbooks available for adoption!
List of Adoptable Cookbooks

Supermarket Belongs to the Community

Supermarket belongs to the community. While Chef has the responsibility to keep it running and be stewards of its functionality, what it does and how it works is driven by the community. The chef/supermarket repository will continue to be where development of the Supermarket application takes place. Come be part of shaping the direction of Supermarket by opening issues and pull requests or by joining us on the Chef Mailing List.

Select Badges

Select Supported Platforms

Select Status

The chef-sugar cookbook has been deprecated

Author provided reason for deprecation:

The chef-sugar cookbook has been deprecated and is no longer being maintained by its authors. Use of the chef-sugar cookbook is no longer recommended.


chef-sugar (39) Versions 5.0.1

Installs chef-sugar. Please see the chef-sugar Ruby gem for more information.

cookbook 'chef-sugar', '= 5.0.1', :supermarket
cookbook 'chef-sugar', '= 5.0.1'
knife supermarket install chef-sugar
knife supermarket download chef-sugar
Quality 50%

Chef Sugar

Gem Version Build Status

Chef Sugar is a Gem & Chef Recipe that includes series of helpful syntactic sugars on top of the Chef core and other resources to make a cleaner, more lean recipe DSL, enforce DRY principles, and make writing Chef recipes an awesome and fun experience!



  • any platform


  • Chef 13.0+


  • none


If you want to develop/hack on chef-sugar, please see the

If you are using Berkshelf, add chef-sugar to your Berksfile:

cookbook 'chef-sugar'

Otherwise, you can use knife or download the tarball directly from the community site:

knife cookbook site install chef-sugar


Simply depend on this cookbook in the metadata of your cookbook and the gem will be installed and required..

Requiring the Chef Sugar Gem will automatically extend the Recipe DSL, Chef::Resource, and Chef::Provider with helpful convenience methods.

Module Method

If you are working outside of the Recipe DSL, you can use the module methods instead of the Recipe DSL. In general, the module methods have the same name as their Recipe-DSL counterparts, but require the node object as a parameter. For example:

In a Recipe:

# cookbook/recipes/default.rb
do_something if windows?

In a Library as a singleton:

# cookbook/libraries/default.rb
def only_on_windows(&block)
  yield if

In a Library as a Mixin:

# cookbook/libraries/default.rb
include Chef::Sugar::PlatformFamily

def only_on_windows(&block)
  yield if windows?(@node)


Note: For the most extensive API documentation, please see the YARD documentation.


Note: Some of the architecture commands begin with an underscore (_) because Ruby does not permit methods to start with a numeric.

  • _64_bit?
  • _32_bit?
  • intel?
  • sparc?
  • ppc64?
  • ppc64le?
  • powerpc?


execute 'build[my binary]' do
  command '...'
  not_if  { _64_bit? }


  • azure?
  • cloud?
  • digitalocean?
  • ec2?
  • eucalyptus?
  • gce?
  • linode?
  • openstack?
  • cloudstack?
  • rackspace?
  • softlayer?


template '/tmp/config' do
    # See also: best_ip_for
    ipaddress: cloud? ? node['local_ipv4'] : node['public_ipv4']

Core Extensions

Note: Core extensions are not included by default. You must require the chef/sugar/core_extensions module manually to gain access to these APIs:

require 'chef/sugar/core_extensions'
  • String#satisfies?
  • String#satisfied_by?
  • Array#satisfied_by?
  • Object#blank?


# Checking version constraints
'1.0.0'.satisfies?('~> 1.0') #=> true
'~> 1.0'.satisfied_by?('1.0') #=> true
# Check for an object's presence
''.blank? #=> true
['hello'].blank? #=> false

Data Bag

  • encrypted_data_bag_item - a handy DSL method for loading encrypted data bag items the same way you load a regular data bag item; this requires Chef::Config[:encrypted_data_bag_secret] is set!
  • encrypted_data_bag_item_for_environment - find the encrypted data bag entry for the current node's Chef environment.
  • data_bag_item_for_environment - find the data bag entry for the current node's Chef environment.


encrypted_data_bag_item('accounts', 'hipchat')
encrypted_data_bag_item_for_environment('accounts', 'github')
data_bag_item_for_environment('accounts', 'github')


Chef Sugar looks for hints to see if the node being converged is a Docker container. When Ohai supports checking other nodes, Chef Sugar will automatically pick up the information.

  • docker?


template '/runme' do
  only_if { docker?(node) }


Chef Sugar adds more Chef-like DSL to attribute definitions. Instead of using the Ruby hash syntax, you can define attributes using nested namespaces. This DSL may be more friendly to non-Ruby developers. It can safely be mixed-and-matched with the standard syntax.

# This is functionally the same as default['apache2']['config']['root'] = '/var/www'
namespace 'apache2' do
  namespace 'config' do
    root '/var/www'
# Specify multiple keys instead of nesting namespaces
namespace 'apache2', 'config' do
  root '/var/www'
# Specify different nested precedence levels
namespace 'apache2', precedence: normal do
  namespace 'config', precedence: override do
    root '/var/www' #=> override['apache2']['config']['root'] = '/var/www'


  • constraints - create a new constraint (or requirement) that can be used to test version validations.
  • chef_version - (DSL only) a wrapper for version(Chef::VERSION)
  • version - create a new version that can be used to test constraint validation.


# Check if a version is satisfied by a constraint
version('1.2.3').satisfies?('~> 1.2.0')
# Check if a constraint is satisfied by a version
constraint('~> 1.2.0').satisfied_by?('1.2.3')
# Support multiple constraints
version('1.2.3').satisfies?('> 1.2', '< 2.0')
constraint('> 1.2', '< 2.0').satisfied_by?('1.2.3')
# Only perform an operation if Chef is at a certain version
package 'apache2' do
  not_if { chef_version.satisfies?('~> 11.0') } # Ignore Chef 11


  • require_chef_gem - "safely" require a gem. Loading a gem with Chef is sometimes difficult and confusing. The errors that Chef produces are also sometimes not very intuitive. In the event you require a gem to exist on the system, you can use require_chef_gem, which will attempt to require the gem and then produce helpful output if the gem is not installed:
    Chef could not load the gem `#{name}'! You may need to install the gem
    manually with `gem install #{name}', or include a recipe before you can
    use this resource. Please consult the documentation for this cookbook
    for proper usage.


require_chef_gem 'pry'
class Chef
  class Provider
    class MyProvider > Provider
      require_chef_gem 'pry'


  • systemd? - detect if init system is systemd
  • upstart? - detect if init system is upstart
  • runit? - detect if init system is runit


systemd_service 'my-service' do
  description 'My Service'
  install do
    wanted_by ''
  service do
    exec_start '/usr/bin/myserviced'
  action [:create, :enable, :start]
  only_if { systemd? }

cookbook_file '/etc/init/my-service.conf' do
  source 'my-service.conf'
  only_if { upstart? }


  • best_ip_for - determine the best IP address for the given "other" node, preferring local IP addresses over public ones.


redis = search('node', 'role:redis').first

template '/tmp/config' do
    ipaddress: best_ip_for(redis)


Additional methods for the node object

  • deep_fetch - safely fetch a nested attribute.
  • deep_fetch! - fetch a nested attribute, raising a more semantic error if the key does not exist.
  • in? - determine if the node is in the given Chef environment.


credentials = if'production')
node.deep_fetch('apache2', 'config', 'root') => node['apache2']['config']['root']


  • amazon_linux?
  • centos?
  • linux_mint?
  • oracle_linux?
  • redhat_enterprise_linux?
  • scientific_linux?
  • ubuntu?
  • solaris2?
  • aix?
  • smartos?
  • omnios?
  • raspbian?
  • nexus?
  • ios_xr?

There are also a series of dynamically defined matchers that map named operating system release versions and comparison operators in the form "#{platform}#{operator}#{name}?". For example:

  • debian_after_squeeze?
  • linuxmint_after_or_at_olivia?
  • mac_os_x_lion?
  • centos_final?
  • ubuntu_before_lucid?
  • ubuntu_before_or_at_maverick?
  • solaris_10?
  • solaris_11?

To get a full list, run the following in IRB:

require 'chef/sugar'
puts Chef::Sugar::Platform.instance_methods


if ubuntu?
  execute 'apt-get update'

Platform Family

  • arch_linux?
  • debian?
  • fedora?
  • freebsd?
  • gentoo?
  • linux?
  • mac_os_x?
  • openbsd?
  • rhel?
  • slackware?
  • suse?
  • windows?
  • wrlinux?


node['attribute'] = if windows?


Note: The applies to the Ruby found at node['languages']['ruby'].

  • ruby_20?
  • ruby_19?


log 'This has been known to fail on Ruby 2.0' if ruby_20?

Run Context

  • includes_recipe? - determines if the current run context includes the recipe
if includes_recipe?('apache2::default')
  apache_module 'my_module' do
    # ...


  • which
  • dev_null
  • installed?
  • installed_at_version?
  • version_for


log "Using `mongo` at `#{which('mongo')}`"

if installed?('apt')
  execute 'apt-get update'

execute 'install[thing]' do
  command "... 2>&1 #{dev_null}"
  not_if  { installed_at_version?('thing', node['thing']['version']) }

log "Skipping git install, version is at #{version_for('mongo', '-v')}"


  • vagrant?


http_request 'http://...' do
  not_if { vagrant? }


  • kvm?
  • lxc?
  • parallels?
  • virtualbox?
  • vmware?
  • openvz?


service 'ntpd' do
  action [:enable, :start]
  not_if { lxc? }


  • at_compile_time - accepts a block of resources to run at compile time
  • before - insert resource in the collection before the given resource
  • after - insert resource in the collection after the given resource


at_compile_time do
  package 'apache2'

# This is equivalent to
package 'apache2' do
  action :nothing
before 'service[apache2]' do
  log 'I am before the apache 2 service fires!'
after 'service[apache2]' do
  log 'I am after the apache 2 service fires!'

License & Authors

Copyright 2013-2015 Seth Vargo

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
See the License for the specific language governing permissions and
limitations under the License.

Dependent cookbooks

This cookbook has no specified dependencies.

Contingent cookbooks

aegir3 Applicable Versions
amazon-ecs-agent Applicable Versions
asdf Applicable Versions
autofs Applicable Versions
automatic_updates Applicable Versions
aws-vpc-nat-instance Applicable Versions
blp-gemrc Applicable Versions
bosun Applicable Versions
boundary_meter Applicable Versions
ceph-chef Applicable Versions
chamber-kibana Applicable Versions
chef-updater Applicable Versions
cobblerd Applicable Versions
consul Applicable Versions
devopsdance-consul-template Applicable Versions
devopsdance-dnsmasq Applicable Versions
devopsdance-policyrcd Applicable Versions
devopsdance-rinetd Applicable Versions
devopsdance-tinyproxy Applicable Versions
elasticsearch Applicable Versions
elk Applicable Versions
elkstack Applicable Versions
embulk Applicable Versions
etcd Applicable Versions
firewall Applicable Versions
frog Applicable Versions
gogs Applicable Versions
hollandbackup Applicable Versions
ice Applicable Versions
ignite-openfire Applicable Versions
il-base Applicable Versions
jenkinsstack Applicable Versions
jmeter Applicable Versions
languages Applicable Versions
machine_tag Applicable Versions
macos Applicable Versions
magentostack Applicable Versions
mesos Applicable Versions
mw_mysql Applicable Versions
mysql-multi Applicable Versions
netrc Applicable Versions
nodestack Applicable Versions
omnibus Applicable Versions
openbazaar Applicable Versions
openssh-lpk Applicable Versions
openssl Applicable Versions
openvpnas Applicable Versions
paramount Applicable Versions
phpstack Applicable Versions
platformstack Applicable Versions
puncha-kibana Applicable Versions
pythonstack Applicable Versions
qgis Applicable Versions
qpdf Applicable Versions
rackops_rolebook Applicable Versions
rackspace_apache_php Applicable Versions
rackspace_gluster Applicable Versions
rackspace_iptables Applicable Versions
rackspace_nginx_php Applicable Versions
rancher Applicable Versions
redis-multi Applicable Versions
rhsm Applicable Versions
rubyinstaller Applicable Versions
sanitize Applicable Versions
snipeit_api Applicable Versions
stack-marathon Applicable Versions
stack_commons Applicable Versions
the_silver_searcher Applicable Versions
ut_base Applicable Versions
varnish Applicable Versions
vscode Applicable Versions
wazuh Applicable Versions
wazuh_agent Applicable Versions
wazuh_manager Applicable Versions
weblogic Applicable Versions
xml Applicable Versions

Chef Sugar Changelog

This file is used to list changes made in each version of the chef-sugar cookbook and gem.

v5.0.1 (2019-03-13)

  • Modifies the behavior of systemd? so that it works equally well on physical/virtual machines as well as within containers.

v5.0.0 (2018-12-26)

  • BREAKING CHANGE: Require Chef 13 or later
  • Trim out test files and the cookbook from the gem artifact to slim install size

v4.2.1 (2018-12-06)

  • Repackaged with an older stove to remove the metadata.rb on the Supermarket for older chef-client releases

v4.2.0 (2018-12-05)

  • Added a new parallels? helper
  • Added support for the Raspberry Pi 1 and Zero to armhf? helper
  • Added a centos_final? helper

v4.1.0 (2018-08-16)

  • Improve the detection of linux hosts with the linux? helper. Amazon Linux and obscure distros will now be properly detected.

v4.0.1 (2018-08-09)

  • Add new Debian, Mint, macOS codenames
  • Add new Ubuntu codenames: artful, bionic, cosmic

v4.0.0 (2018-01-26)

  • Require Ruby 2.2 or later and Chef 12.10 or later
  • Cookbook now installs the chef-sugar gem via a metadata installation so chef-sugar::default on your runlist is no longer needed
  • Added additional metadata to the cookbook: supports, issue_url, source_url, chef_version.
  • Requirements improved in the readme

v3.6.0 (2017-10-26)

  • Add Ubuntu zesty and debian stretch detection
  • Add softlayer? helper
  • Add aarch64? helper

v3.5.0 (2016-07-12)

  • Improve the systemd check to not fail on older kernels or Windows hosts
  • Add detection of macOS 10.11 and 10.12

v3.4.0 (2016-07-18)


  • Add virtual? and physical? methods
  • Add Scaleway C1 server (arm arch) support
  • Add IMB s390x support
  • Add missing Ubuntu release names

Bug Fixes

  • Drop Ruby 2.0.0 support from Travis test matrix
  • Pin to Rack 1.6 (dev dep)

v3.3.0 (2016-01-11)


  • Break up Chef::Sugar::Constraints into a class and a dsl file
  • Add platform_version method with full constraints comparison support

v3.2.0 (2015-12-10)


  • Add platform matchers for debian and fedora
  • Add openvz support under virtualization
  • Add init system detection support
  • Add support for nexus, ios_xr platforms and wrlinux platform_family
  • Add additional aix helpers

Bug Fixes

  • Properly expose Architecture#i386? in the DSL

v3.1.1 (2015-06-23)


  • Update Intel CPU types based on existing Fauxhai data
  • Update SPARC logic and 32/64-bit logic for x86 and i386

Bug Fixes

  • Fix 32-bit logic
  • Fix default behavior to include chef-sugar at compile time
  • Fix Chef 12.1.0 warnings for chef_gem compile time install
  • Fix redhat_enterprise_linux? matcher

v3.0.2 (2015-03-26)


  • Add helpers for ppc64 and ppc64le architecture

Bug Fixes

  • Adjustments to error message

v3.0.1 (2015-03-20)

Breaking Changes

  • Rename compile_time to at_compile_time - if your recipes are affected by this breaking change, your Chef Client run will produce a verbose error message with details on how to fix the error.

v3.0.0 (2015-03-17)

Breaking Changes

  • Drop support for Ruby 1.9 (it might still work, but it is no longer officially supported)


  • Remove accidentially committed gem source
  • Bump development dependencies
  • Add digitalocean? matcher
  • Expose the rhel platform as el
  • Add ppc64le platform
  • Add helper for determining if architecture is SPARC
  • Add helper for determining if architecture is Intel
  • Add dynamic platform/version matchers for Solaris

Bug Fixes

  • Reset namespace_options when reaching top-level resources

v2.5.0 (2015-01-05)


  • Add data_bag_item_for_environment function
  • Add kvm? matcher
  • Add virtualbox? matcher

Bug Fixes

  • Use .key? to check for hash key presence, raising an AttributeDoesNotExist error sooner

v2.4.1 (2014-10-12)

  • No changes from v2.4.0 - forced a new version upload to the Chef Supermarket

v2.4.0 (2014-10-12)


  • Add docker? matcher

v2.3.2 (2014-10-07)

Big Fixues

  • Include amd64 in _64_bit? check

v2.3.1 (2014-10-07)


  • Check all 64-bit architectures that may be reported by Ohai

Bug Fixes

  • Be more tolerant of nil values return from sub functions
  • Check to make sure node['domain'] is not nil before calling #include?

v2.3.0 (2014-09-24)


  • Add vmware? matcher
  • Allow the attribute DSL to access parent attributes

Bug Fixes

  • Return true or false from all Boolean methods (instead of nil or truthy values)

v2.2.0 (2014-08-20)


  • Add smartos? matcher
  • Add omnios? matcher

v2.1.0 (2014-06-26)


  • Add solaris2? matcher
  • Add aix? matcher
  • Add 'lxc?' matcher

Bug Fixes

  • Fix a bug in namespace memoization during attribute initialization

v2.0.0 (2014-06-16)


  • Remove not_linux? method
  • Remove not_windows? method


  • Miscellaneous spelling fixes
  • Update a failing unit test for installed?
  • Add Mac OS X to the list of platforms (Yosemite)
  • Upgrade to RSpec 3
  • Fix which (and installed? and installed_at_version?) when given an absolute path
  • Fix linux? check to only return true on real linuxes

v1.3.0 (2014-05-05)

  • Check both $stdout and $stderr in version_for
  • Add additional platform versions
  • Make includes_recipe? a top-level API (instead of just Node)
  • Match on the highest version number instead of direct equality checking on platform versions
  • Define Object#blank? as a core extension
  • Define String#flush as a core extension
  • Remove Stove

v1.2.6 (2014-03-16)

  • Fix a bug in vagrant? returning false on newer Vagrant versions
  • Remove Coveralls

v1.2.4 (2014-03-13)

  • See (1.2.2), but I botched the release

v1.2.2 (2014-03-13)

  • Fix a critical bug with encrypted_data_bag_item using the wrong key

v1.2.0 (2014-03-09)

  • Add namespace functionality for specifying attributes in a DSL
  • Add constraints helpers for comparing version strings
  • Add require_chef_gem to safely require and degrade if a gem is not installed
  • Add deep_fetch and deep_fetch! to fetch deeply nested keys
  • Accept an optional secret key in encrypted_data_bag_item helper and raise a helpful error if one is not set (NOTE: this changes the airity of the method, but it's backward-compatible because Ruby is magic)
  • Add Stove for releasing
  • Updated copyrights for 2014

v1.1.0 (2013-12-10)

  • Add cloudstack? helper
  • Add data bag helpers
  • Remove foodcritic checks
  • Upgrade development gem versions
  • Randomize spec order

v1.0.1 (2013-10-15)

  • Add development recipe
  • Add compile_time, before, and after filters

v1.0.0 (2013-10-15)

  • First public release

Collaborator Number Metric

5.0.1 passed this metric

Contributing File Metric

5.0.1 failed this metric

Failure: To pass this metric, your cookbook metadata must include a source url, the source url must be in the form of, and your repo must contain a file

Foodcritic Metric

5.0.1 passed this metric

No Binaries Metric

5.0.1 passed this metric

Testing File Metric

5.0.1 failed this metric

Failure: To pass this metric, your cookbook metadata must include a source url, the source url must be in the form of, and your repo must contain a file

Version Tag Metric

5.0.1 failed this metric

Failure: To pass this metric, your cookbook metadata must include a source url, the source url must be in the form of, and your repo must include a tag that matches this cookbook version number