Chef

Table Of Contents

env

A resource is a key part of a recipe that defines the actions that can be taken against a piece of the system. These actions are identified during each chef-client run as the resource collection is compiled. Once identified, each resource (in turn) is mapped to a provider, which then configures each piece of the system.

The env resource is used to manage environment keys in Microsoft Windows. After an environment key is set, Microsoft Windows must be restarted before the environment key will be available to the Task Scheduler.

Note

On UNIX-based systems, the best way to manipulate environment keys is with the ENV variable in Ruby; however, this approach does not have the same permanent effect as using the env resource.

Syntax

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

env "name" do
  attribute "value" # see attributes section below
  ...
  action :action # see actions section below
end

where

  • env tells the chef-client to use the Chef::Provider::Env::Windows provider during the chef-client run
  • name is the name of the resource block; when the key_name attribute is not specified as part of a recipe, name is also the name of the environment key that is created, deleted, or modified
  • attribute is zero (or more) of the attributes that are available for this resource
  • :action is the step that the resource will ask the provider to take during the chef-client run

Actions

This resource has the following actions:

Action Description
:create Default. Use to create a new environment variable.
:delete Use to delete an environment variable.
:modify Use to modify an existing environment variable. This will append the new value to the existing value, using the delimiter specified by the delim attribute.

Attributes

This resource has the following attributes:

Attribute Description
delim The delimiter that is used to separate multiple values for a single key.
key_name The name of the key that will be created, deleted, or modified. Default value: the name of the resource block (see Syntax section above).
provider Optional. Use to specify a provider by using its long name. For example: provider Chef::Provider::Long::Name. See the Providers section below for the list of providers available to this resource.
value The value with which key_name is set.

Providers

The following providers are available. Use the short name to call the provider from a recipe:

Long name Short name Notes
Chef::Provider::Env::Windows env The default provider for all Microsoft Windows platforms.

Examples

The following examples demonstrate various approaches for using resources in recipes. If you want to see examples of how Chef uses resources in recipes, take a closer look at the cookbooks that Chef authors and maintains: https://github.com/opscode-cookbooks.

Set an environment variable

env "ComSpec" do
  value "C:\\Windows\\system32\\cmd.exe"
end