machine_image

[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.

Warning

This functionality was available with Chef Provisioning and was packaged in the ChefDK.

Chef Provisioning was officially end-of-life on August 31, 2019 and is no longer included with ChefDK. The Chef Provisioning source code and drivers have been moved into the chef-boneyard organization. If you are a current user of Chef Provisioning, please contact your Chef Customer Success Manager or Account Representative to review your options.

Syntax

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
end

where

  • machine_image tells Chef Infra Client to use the Chef::Provider::MachineImage provider during a Chef Infra 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 Chef Infra Client will take to bring the node into the desired state

Actions

This resource has the following actions:

:archive
Use to archive a machine image.
:create
Default. Use to create a machine image.
:destroy
Use to destroy a machine image.
:nothing
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 a Chef Infra Client run.

Properties

This resource has the following properties:

attributes
Use to specify a hash of attributes to be applied to the machine image.
chef_environment
The name of the environment.
complete
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.
image_options

Ruby Type: Hash

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

name
The name of the machine image.
raw_json

The machine image as JSON data. For example:

{

}
recipe
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.
remove_recipe
Use to remove a recipe from the run-list for the machine image.
remove_role
Use to remove a role from the run-list for the machine image.
role
Use to add a role to the run-list for the machine image.
run_list
Use to specify the run-list to be applied to the machine image. See About Run Lists for more information.
tags
Use to specify the list of tags to be applied to the machine image. Any tag not specified in this list will be removed.

Examples

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'
end

machine 'web_machine' do
 from_image 'web_image'
end