Know about metadata.rb and metadata.json in chef

What is Metadata in chef?

In order to understand cookbooks without evaluating them every files, we generate metadata about cookbooks

What is metadata.rb?

Before unerstanding about metadata.json, we need to understand about metadata.rb.

Every cookbook requires a small amount of metadata. Metadata is stored in a file called metadata.rb that lives at the top of each cookbook’s directory. The contents of the metadata.rb file provides hints to the Chef server so that cookbooks are deployed to each node correctly.

A metadata.rb file is never interpreted directly. Rather, the metadata.rb file provides a simple location to store and edit data that is then compiled by the Chef server and stored as JSON data. 

Metadata is compiled whenever ....

1. a cookbook is uploaded to the Chef server or 

2. when the knife cookbook metadata subcommand is run. knife creates a metadata.rb file automatically whenever the knife cookbook create subcommand is run.


metadata.json is generated from metadata.rb. to generate or regenerate the Chef cookbook metadata, which creates a new 'metadata.json' file from the 'metadata.rb' file.

From the command line of your Chef development server, enter the following command:

# knife cookbook metadata my-cookbook -o <COOKBOOK_PATH>

Example:  # knife cookbook metadata my-cookbook-name -o /opt/development/cookbooks/

A metadata.json file can be edited directly, should temporary changes be required. Any subsequent upload or action that generates metadata will cause the existing metadata.json file to be overwritten with the newly generated metadata. Therefore, any permanent change to metadata that is required should only be made in the metadata.rb file.

What if metadata.rb and metadata.json both are present in cookbooks?

If a cookbook contains both a metadata.rb and metadata.json at cookbook load time, the metadata.rb will be preferred. This should be swapped around to ensure that dynamically built metadata which has been compiled is read properly without error.

knife cookbook upload reads metadata.rb and ignores metadata.json. It generates the data from the .rb file, and uploads that. It does not create a metadata.json file, on disk or in the cookbook itself--this is just metadata in the cookbook object.

Rate this item
(1 Vote)
Rajesh Kumar


Total, Over 12 years of extensive experience in the Software Configuration Management domain having depth knowledge of DevOps, Continuous Integration and Delivery, Configuration Management, Build and Installer, Release Management and Application Management.

What corporate management say about us?

Rajesh is very good trainer with very good technical knowledge. He was able to resolve our queries effectively with the proper live example.The session was very helpful and interactive. Overall satisfied with the training.<br />

Rahul Ruhela
Sep 02, 2016