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

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

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 the Chef 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.

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:

'role[NAME]'

or

'recipe[COOKBOOK::RECIPE]'

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

'recipe[COOKBOOK::RECIPE],COOKBOOK::RECIPE,role[NAME]'
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