Skip to main content

Publish Cookbooks to Multiple Chef Infra Servers

[edit on GitHub]



This documentation applies to a deprecated product. Chef Automate includes newer out-of-the-box compliance profiles, an improved compliance scanner with total cloud scanning functionality, better visualizations, role-based access control and many other features. Chef Automate is included as part of the Workflow license agreement and is available via subscription.

The delivery-sugar cookbook exposes some libraries and a resource that you can use to publish a cookbook (or multiple cookbooks) to multiple Chef servers or organizations. The following examples show how to publish to both a single Chef Infra Server and how to extend that methodology to publish to multiple Chef servers.


Before you begin, you must copy the config.rb file and the client key .pem file (referenced as client_key in config.rb) to the build nodes/runners that you will use in the build-cookbook. This can be done manually by logging in to the build nodes/runners and copying the files or automated through the use of a secure copy tool like scp.

The following is an example of a config.rb file for a test user that points to the Chef Infra Server and the organization your_org. The test.pem file is the value specified in the client_key setting.

current_dir = File.dirname(__FILE__)
log_location      STDOUT
node_name         'test'
client_key        "#{current_dir}/test.pem"
trusted_certs_dir '/etc/chef/trusted_certs'
chef_server_url   ''

Publish a cookbook to a single Chef server

To publish a cookbook to a Chef Infra Server, use the delivery_chef_cookbook resource and reference the config.rb file that you copied to your build node/runner.

This example shows how to publish a cookbook called rally to a single Chef Infra Server.

knife_rb = '/path/to/the/knife_rb/file/in/the/build-node/config.rb'

delivery_chef_cookbook 'rally' do
  path '/path/to/the/cookbook/in/the/build-node/rally'


The default action for delivery_chef_cookbook is :upload, so you do not need to explicitly include that in your delivery_chef_cookbook implementation.

Publish Cookbook to Multiple Chef servers

Publishing to multiple servers uses the delivery_chef_cookbook in much the same way as publishing to a single Chef Infra Server except you reference multiple Chef Infra Server objects through an array.

In the following example, imagine you have two Chef servers, one in San Francisco and another one in New York. Also, assume you have copied the correct config.rb and client_key files to the build nodes/runners for each Chef Infra Server.

For this particular example, you want the cookbook uploaded at the very end of the workflow pipeline, in the Functional phase of the Delivered Stage. This requires that you modify the Functional recipe (recipes/functional.rb) of the build-cookbook within your project, as shown below.

# Run it only in Delivered::Functional
# This helper is coming from delivery-sugar
# =>,L113
if delivery_environment.eql?('delivered')

  # Previously generated config.rb files
  ny_knife_rb = '/var/opt/delivery/workspace/chef_servers/ny/config.rb'
  sf_knife_rb = '/var/opt/delivery/workspace/chef_servers/sf/config.rb'

  # ChefServer Objects
  chef_server_ny =
  chef_server_sf =

  delivery_chef_cookbook delivery_project do
    path delivery_workspace_repo
    chef_server [chef_server_ny, chef_server_sf]