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.
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.
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
This resource has the following actions:
|: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.|
This resource has the following attributes:
|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.|
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.|
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