knife environment

An environment is a way to map an organization’s real-life workflow to what can be configured and managed when using Chef server. Every organization begins with a single environment called the _default environment, which cannot be modified (or deleted). Additional environments can be created to reflect each organization’s patterns and workflow. For example, creating production, staging, testing, and development environments. Generally, an environment is also associated with one (or more) cookbook versions.

The knife environment subcommand is used to manage environments within a single organization on the Chef server.

Note

Review the list of common options available to this (and all) knife subcommands and plugins.

create

Use the create argument to add an environment object to the Chef server. When this argument is run, knife will open $EDITOR to enable editing of the ENVIRONMENT description field (unless a description is specified as part of the command). When finished, knife will add the environment to the Chef server.

Syntax

This argument has the following syntax:

$ knife environment create ENVIRONMENT_NAME -d DESCRIPTION

Options

This argument has the following options:

--description DESCRIPTION
The description of the environment. This value populates the description field for the environment on the Chef server.

Note

See knife.rb for more information about how to add certain knife options as settings in the knife.rb file.

Examples

The following examples show how to use this knife subcommand:

Create an environment

To create an environment named dev with a description of The development environment.:

$ knife environment create dev --description "The development environment."

delete

Use the delete argument to delete an environment from a Chef server.

Syntax

This argument has the following syntax:

$ knife environment delete ENVIRONMENT_NAME

Options

This command does not have any specific options.

Examples

The following examples show how to use this knife subcommand:

Delete an environment

To delete an environment named dev, enter:

$ knife environment delete dev

Type Y to confirm a deletion.

edit

Use the edit argument to edit the attributes of an environment. When this argument is run, knife will open $EDITOR to enable editing of ENVIRONMENT attributes. When finished, knife will update the Chef server with those changes.

Syntax

This argument has the following syntax:

$ knife environment edit ENVIRONMENT_NAME

Options

This command does not have any specific options.

Examples

The following examples show how to use this knife subcommand:

Edit an environment

To edit an environment named devops, enter:

$ knife environment edit devops

from file

Use the from file argument to add or update an environment using a JSON or Ruby DSL description.

Syntax

This argument has the following syntax:

$ knife environment from file FILE (options)

Options

This argument has the following options:

-a, --all
Upload all environments found at the specified path.

Note

See knife.rb for more information about how to add certain knife options as settings in the knife.rb file.

Examples

The following examples show how to use this knife subcommand:

Create an environment from a JSON file

To add an environment using data contained in a JSON file:

$ knife environment from file "path to JSON file"

list

Use the list argument to list all of the environments that are currently available on the Chef server.

Syntax

This argument has the following syntax:

$ knife environment list -w

Options

This argument has the following options:

-w, --with-uri
Show the corresponding URIs.

Examples

The following examples show how to use this knife subcommand:

View a list of environments

To view a list of environments:

$ knife environment list -w

show

Use the show argument to display information about the specified environment.

Syntax

This argument has the following syntax:

$ knife environment show ENVIRONMENT_NAME

Options

This argument has the following options:

-a ATTR, --attribute ATTR
The attribute (or attributes) to show.

Examples

The following examples show how to use this knife subcommand:

Show environments

To view information about the dev environment enter:

$ knife environment show dev

to return:

% knife environment show dev
chef_type:            environment
cookbook_versions:
default_attributes:
description:
json_class:           Chef::Environment
name:                 dev
override_attributes:

\\
\\
\\
\\

Show environments as JSON

To view information in JSON format, use the -F common option as part of the command like this:

$ knife environment show devops -F json

Other formats available include text, yaml, and pp.