[edit on GitHub]

Use the machine_image resource to define a machine image. This image may then be used by the machine resource when building machines.


This functionality is available with Chef provisioning and is packaged in the Chef development kit. Chef provisioning is a framework that allows clusters to be managed by the chef-client and the Chef server in the same way nodes are managed: with recipes. Use Chef provisioning to describe, version, deploy, and manage clusters of any size and complexity using a common set of tools.


The syntax for using the machine_image resource in a recipe is as follows:

machine_image 'name' do
  attribute 'value' # see properties section below
  action :action # see actions section below


  • machine_image tells the chef-client to use the Chef::Provider::MachineImage provider during the chef-client run
  • name is the name of the resource block and also the name of the machine image
  • attribute is zero (or more) of the properties that are available for this resource
  • action identifies which steps the chef-client will take to bring the node into the desired state


This resource has the following actions:

Use to archive a machine image.
Default. Use to create a machine image.
Use to destroy a machine image.
This resource block does not act unless notified by another resource to take action. Once notified, this resource block either runs immediately or is queued up to run at the end of the Chef Client run.


This resource has the following properties:

Use to specify a hash of attributes to be applied to the machine image.
The name of the environment.
Use to specify if all of the attributes specified in attributes represent a complete specification for the machine image. When true, any attributes not specified in attributes will be reset to their default values.

Ruby Type: Hash

Use to specify options that are used with this machine image.

The name of the machine image.

The machine image as JSON data. For example:


Use to add a recipe to the run-list for the machine image. Each recipe adds a single recipe to the run-list. The order in which recipe defines the run-list is the order in which Chef will execute the run-list on the machine image.
Use to remove a recipe from the run-list for the machine image.
Use to remove a role from the run-list for the machine image.
Use to add a role to the run-list for the machine image.

Use to specify the run-list to be applied to the machine image.

A run-list defines all of the information necessary for Chef to configure a node into the desired state. A run-list is:

  • An ordered list of roles and/or recipes that are run in the exact order defined in the run-list; if a recipe appears more than once in the run-list, the chef-client will not run it twice
  • Always specific to the node on which it runs; nodes may have a run-list that is identical to the run-list used by other nodes
  • Stored as part of the node object on the Chef server
  • Maintained using knife and then uploaded from the workstation to the Chef server, or maintained using Chef Automate

A run-list must be in one of the following formats: fully qualified, cookbook, or default. Both roles and recipes must be in quotes, for example:




Use a comma to separate roles and recipes when adding more than one item the run-list:

Use to specify the list of tags to be applied to the machine image. Any tag not specified in this list will be removed.


The following examples demonstrate various approaches for using resources in recipes:

Build a machine from a machine image

machine_image 'web_image' do
  recipe 'apache2'

machine 'web_machine' do
 from_image 'web_image'