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


consul (79) Versions 1.4.2

Application cookbook which installs and configures Consul.

cookbook 'consul', '= 1.4.2', :supermarket
cookbook 'consul', '= 1.4.2'
knife supermarket install consul
knife supermarket download consul
Quality 0%


Build Status
Code Quality
Cookbook Version

Application cookbook which installs and configures Consul.

Consul is a tool for discovering and configuring services within your
infrastructure. This is an application cookbook which takes a
simplified approach to configuring and installing
Consul. Additionally, it provides Chef primitives for more advanced

Basic Usage

For most infrastructure we suggest first starting with the default
recipe. This installs and configures Consul from the latest supported
release. It is also what is used to certify platform support through
the use of our integration tests.

This cookbook provides node attributes which are used to fine tune
the default recipe which installs and configures Consul. These values
are passed directly into the Chef resource/providers which are exposed
for more advanced configuration.

Out of the box the following platforms are certified to work and are
tested using our Test Kitchen configuration. Additional platforms
may work, but your mileage may vary.

  • CentOS (RHEL) 5.11, 6.7, 7.2
  • Ubuntu 12.04, 14.04
  • Windows 2012


Out of the box the default recipe installs and configures the Consul
agent to run as a service in client mode. The intent here is that
your infrastructure already has a quorum of servers. In order
to configure Consul to connect to your cluster you would supply an
array of addresses for the Consul agent to join. This would be done
in your wrapper cookbook:
node.default['consul']['config']['start_join'] = %w{}


This cookbook is designed to allow for the flexibility to bootstrap a
new cluster. The best way to do this is through the use of a
wrapper cookbook which tunes specific node attributes for a
production server deployment.

The Consul cluster cookbook is provided as an example.

Advanced Usage

As explained above this cookbook provides Chef primitives in the form
of resource/provider to further manage the install and configuration
of Consul. These primitives are what is used in the default recipe,
and should be used in your own wrapper cookbooks for more
advanced configurations.


It is very important to understand that each resource/provider has
defaults for some properties. Any changes to a resource's default
properties may need to be also changed in other resources. The best
example is the Consul configuration directory.

In the example below we're going to change the configuration file from
the default (/etc/consul.json) to one that may be on a special volume.
It is obvious that we need to change the path where consul_config
writes its file to, but it is less obvious that this needs to be
passed into consul_service.

Inside of a recipe in your wrapper cookbook you'll want to do
something like the following block of code. It uses the validated
input from the configuration resource and passes it into the service
resource. This ensures that we're using the same data.
config = consul_config '/data/consul/default.json'
consul_service 'consul' do
config_file config.path


In order to provide an idempotent implementation of Consul
watches and definitions. We write these out as
a separate configuration file in the JSON file format. The provider
for both of these resources are identical in functionality.

Below is an example of writing a Consul service definition for
the master instance of Redis. We pass in several parameters and tell
the resource to notify the proper instance of the Consul service to
consul_definition 'redis' do
type 'service'
parameters(tags: %w{master}, address: '', port: 6379)
notifies :reload, 'consul_service[consul]', :delayed

A check definition can easily be added as well. You simply have
to change the type and pass in the correct parameters. The definition
below checks memory utilization using a script on a ten second interval.
consul_definition 'mem-util' do
type 'check'
parameters(script: '/usr/local/bin/', interval: '10s')
notifies :reload, 'consul_service[consul]', :delayed

Finally, a watch is created below to tell the agent to monitor to
see if an application has been deployed. Once that application is
deployed a script is run locally. This can be used, for example, as a
lazy way to clear a HTTP disk cache.
consul_watch 'app-deploy' do
type 'event'
parameters(handler: '/usr/local/bin/')
notifies :reload, 'consul_service[consul]', :delayed

A keen eye would notice that we are delaying the reload of the Consul
service instance
. The reason we do this is to minimize the number of
times we need to tell Consul to actually reload configurations. If
there are several definitions this may save a little time off your
Chef run.


The consul_acl resource allows management of Consul ACL rules. Supported
actions are :create and :delete. The :create action will update/insert
as necessary.

The consul_acl resource requires the Diplomat Ruby API gem to be
installed and available to Chef before using the resource. This can be
accomplished by including consul::client_gem recipe in your run list.

In order to make the resource idempotent and only notify when necessary, the
id field is always required (defaults to the name of the resource).
If type is not provided, it will default to "client". The acl_name
and rules attributes are also optional; if not included they will be empty
in the resulting ACL.

The example below will create a client ACL token with an ID of the given UUID,
Name of "AwesomeApp Token", and Rules of the given string.
consul_acl '49f06aa9-782f-465a-becf-44f0aaefd335' do
acl_name 'AwesomeApp Token'
type 'client'
rules <<-EOS.gsub(/^\s{4}/, '')
key "" {
policy = "read"
service "" {
policy = "write"
auth_token node['consul']['config']['acl_master_token']


The command-line agent provides a mechanism to facilitate remote
execution. For example, this can be used to run the uptime command
across your fleet of nodes which are hosting a particular API service.
consul_execute 'uptime' do
options(service: 'api')

All of the options available on the command-line can be passed
into the resource. This could potentially be a very dangerous
operation. You should absolutely understand what you are doing. By the
nature of this command it is impossible for it to be idempotent.


consul_ui resource can be used to download and extract the
consul web UI.
It can be done with a block like this:

consul_ui 'consul-ui' do
  owner node['consul']['service_user']
  group node['consul']['service_group']
  version node['consul']['version']

Assuming consul version 0.5.2 above block would create /srv/consul-ui/0.5.2
and symlink /srv/consul-ui/current.

It does not change agent's configuration by itself.
consul_config resource should be modified explicitly in order to host the web page.

consul_config 'consul' do
  ui_dir '/srv/consul-ui/current/dist'

This is optional, because consul UI can be hosted by any web server.

Change Log

All notable changes to this project will be documented in this file.
This project adheres to Semantic Versioning.



  • PR#275 Add integration tests for Windows.

Bug Fixes

  • PR#274 Fix start issues with EL5.
  • PR#273 Fix data directory attribute for Windows.


Bug Fixes

  • PR#271 Fix service user not having /bin/bash shell.



This release includes general improvements to the build process and
adds newer versions of EL6 and EL7 to the build matrix. Additionally,
the following enhancements:
- PR#259 Add windows support. @Ginja
- PR#266 Add custom template for sysvinit. @legal90
- PR#264 Bump default version to Consul 0.6.3.
- PR#267 Add parameters for retry join configuration.

Bug Fixes

  • PR#226 Fix systemd unit starting before network.
  • PR#235 Fix EL6 service not starting at boot.
  • PR#269 Fix duplicate data directory attributes.
  • PR#270 Fix regression of absolute path for systemd unit.


Bug Fixes

  • Fixes constraints on cookbooks for builds.
  • Modifies chef-vault cookbook entry to use upstream.



  • Travis builds now use new container infrastructure.
  • PR#215 Add new resource for managing Consul UI service.
  • PR#219 Adds support to configuration for recursor. @fumimaron9
  • PR#224 Adds support to configuration resource for Join WAN. @justintime
  • PR#228 Default recipe now opens up UDP firewall rules. @twmb

Bug Fixes


Bug Fixes

  • Locks to Chef 11 compatible version of libarchive cookbook.



  • Adds support for publishing to statsd URL. @akerekes
  • Adds support for Arch Linux. (@logankoester)
  • Adds systemd init style. @logankoester
  • Adds support for Consul HTTP checks. @gavinheavyside
  • Bump default Consul installed version to 0.5.0 ### Bug Fixes
  • Remove hard dependency on chef-provisioning cookbook.
  • Sets correct ownership to Consul run user/group on service directories. @thedebugger
  • Removes support for EL5 (CentOS 5) and Ubuntu 10.04.


Bug Fixes

  • Export GOMAXPROCS when using runit service style.


Bug Fixes

  • Sets GOMAXPROCS when using runit service style.


Bug Fixes

  • Vanilla init script now points to the proper Consul binary and data dir.



  • Upgrading from one version to another of Consul is now supported.
  • Restarts after upgrade.

Bug Fixes

  • Partial convergeances will now gracefully recover on the next chef run.
  • Upstart will now respawn Consul on crash.
  • It is no longer possible to set an invalid install method.



  • Adds cluster recipe for easily provisioning new Consul clusters.
  • Adds support for additional options for service_config.
  • Adds support for Ubuntu 10.04.
  • Allows custom data bags for Consul encrypt.
  • Bumps support for golang cookbook to 1.4.
  • Adds consul/retry_on_join attribute.
  • Adds consul_service_watch LWRP.

Bug Fixes

  • Reloading the Consul service when using runit init style.

Foodcritic Metric

1.4.2 failed this metric

FC019: Access node attributes in a consistent manner: /tmp/cook/5a2d9c88e8eb5d68845f77be/consul/libraries/consul_service.rb:164
FC023: Prefer conditional attributes: /tmp/cook/5a2d9c88e8eb5d68845f77be/consul/libraries/consul_service_windows.rb:76
FC044: Avoid bare attribute keys: /tmp/cook/5a2d9c88e8eb5d68845f77be/consul/attributes/default.rb:17