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


version_databag (1) Versions 1.0.0

Dynamically retrieve artifact versions from a data bag

cookbook 'version_databag', '~> 1.0.0'
cookbook 'version_databag', '~> 1.0.0', :supermarket
knife cookbook site install version_databag
knife cookbook site download version_databag


Cookbook Version Build Status

A Chef cookbook that provides functionality to dynamically retrieve artifact versioning information from a configurable Chef data bag. Note, this cookbook requires a minimum version of Chef 12.3.0 to be able to be used.


All attributes are under the scope of the cookbook name: "version_databag"

key Type Description Default
version_type String The type of version to retrieve from the databag "release"
databag String The databag containing the version data nil
databag_item String The databag item containing the version data nil
artifact_override_map Hash A hash of artifact_name => version_type to override the base version_type for the specified artifact nil
artifact_specifications Array An array of hashes containing the artifact specification. The artifact specification includes artifact_name, attribute_path, and optionally value_substitution nil
delimiter String A one or two character String of a delimiter when using value substitution "<>"


default - Accepts an array of hashes containing artifact_name, attribute_path, and optionally a value_substitutions. This recipe calls the attrib_interpolate provider for each artifact specification in the array assuming they are defined along with the location of the data bag and data bag item. If an individual hash does not contain both required values (artifact_name and attribute path), that hash will be skipped with a log message of the index of the offending hash in the array.

Example recipe call with an artifact specification and a value substitution:

'version_databag' => {
  'databag' => 'Artifacts',
  'databag_item' => 'versions',
  'artifact_specifications' => [
      'artifact_name' => 'Artifact1',
      'attribute_path' => "['application_cookbook']['version']"
      'artifact_name' => 'Artifact2',
      'value_substitution' => "<Artifact2>/",
      'attribute_path' => "['reference_git']['item']"

Example of the sample Artifacts/versions data bag that contains the versions referenced above:

  "id": "versions",
  "Artifact1": {
    "release": "3.17",
    "snapshot": "3.18-SNAPSHOT"
  "Artifact2": {
    "release": "1.0"
  "Artifact3": {
    "release": "1.3",
    "snapshot": "1.4.SNAPSHOT"

After the execution of the above recipe, the following code would contain these results:

#=> 3.17



attrib_interpolate - Handles the logic to derive an artifact version from a given artifact_name from the defined data bag and populates the corresponding attribute_path. Alternatively, the provider can substitute the version into a string using the delimited artifact name as a value substitution. The provider is available to pass dynamically named artifacts or artifacts defined in a wrapper cookbook's attributes. Note: the provider call should be executed in Chef's "compile phase" to allow the attributes to be available as downstream cookbooks execute during the "execution phase".

Examples below reference the same Artifacts/version data bag previously mentioned.

Example 1: Assign the artifact version to the attribute_path through a calling cookbook with an artifact_override_map

Configured attributes:

default_attributes 'application_cookbook' => {
  'artifacts' => ['Artifact1', 'Artifact3']
  "version_databag" => {
    "databag" => "Artifacts",
    "databag_item" => "versions",
    "artifact_override_map" => {
      "Artifact3" => "snapshot"

Cookbook code:

node['application_cookbook']['artifacts'].each do |artifact|
  version_databag_attrib_interpolate "Determine the version of #{artifact}" do
    artifact_name artifact
    attribute_path "['application_cookbook']['#{artifact}']['version']"
    action :nothing


#=> 3.17

#=> 1.4.SNAPSHOT

Example 2: Substitute the version into a value substitution string with a custom delimiter

Configured attributes:

default_attributes 'version_databag' => {
  'databag' => 'Artifacts',
  'databag_item' => 'versions',
  'delimiter' => '|'

Cookbook code:

version_databag_attrib_interpolate "Determine artifact version git value substitution" do
  artifact_name 'Artifact2'
  attribute_path "['reference_git']['item']"
  value_substitution "|Artifact2|/"
  action :nothing




How to run tests

To run the tests for this cookbook you must install ChefDK.

The unit tests are written with rspec and chefspec. They can be run with chef exec rspec.

The lint testing uses Foodcritic and can be run with chef exec foodcritic . -f any.




Copyright 2015 Cerner Innovation, Inc.

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, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Dependent cookbooks

This cookbook has no specified dependencies.

Contingent cookbooks

There are no cookbooks that are contingent upon this one.

version_databag cookbook CHANGELOG

This file is used to list changes made in each version of the version_databag cookbook.

1.0 (yyyy-mm-dd)

  • The 1.0 release of the version_databag cookbook

Collaborator Number Metric

1.0.0 failed this metric

Failure: Cookbook has 0 collaborators. A cookbook must have at least 2 collaborators to pass this metric.

Contributing File Metric

1.0.0 passed this metric

Foodcritic Metric

1.0.0 passed this metric

License Metric

1.0.0 failed this metric

version_databag does not have a valid open source license.
Acceptable licenses include Apache-2.0, apachev2, Apache 2.0, MIT, mit, GPL-2.0, gplv2, GNU Public License 2.0, GPL-3.0, gplv3, GNU Public License 3.0.

No Binaries Metric

1.0.0 passed this metric

Publish Metric

1.0.0 passed this metric

Supported Platforms Metric

1.0.0 passed this metric

Testing File Metric

1.0.0 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

1.0.0 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