KNIFE-DATA-BAG(1)

NAME
knife-data-bag - The man page for the knife data bag subcommand.

A data bag is a global variable that is stored as JSON data and is accessible from a server. A data bag is indexed for searching and can be loaded by a recipe or accessed during a search. The contents of a data bag can vary, but they often include sensitive information (such as database passwords).

A data bag item may be encrypted using shared secret encryption. This allows each data bag item to store confidential information (such as a database password) or to be managed in a source control system (without plain-text data appearing in revision history). Each data bag item may be encrypted individually; if a data bag contains multiple encrypted data bag items, these data bag items are not required to share the same encryption keys.

The knife data bag subcommand is used to manage arbitrary stores of globally available JSON data.

COMMON OPTIONS

The following options may be used with any of the arguments available to the knife data bag subcommand:

--chef-zero-port PORT
    The port on which chef-zero will listen.

-c CONFIG_FILE, --config CONFIG_FILE
    The configuration file to use.

-d, --disable-editing
    Indicates that $EDITOR will not be opened; data will be accepted as-is.

--defaults
    Indicates that Knife will use the default value, instead of asking a user to provide one.

-e EDITOR, --editor EDITOR
    The $EDITOR that is used for all interactive commands.

-E ENVIRONMENT, --environment ENVIRONMENT
    The name of the environment. When this option is added to a command, the command will run only against the named environment.

-F FORMAT, --format FORMAT
    The output format: summary (default), text, json, yaml, and pp.

-h, --help
    Shows help for the command.

-k KEY, --key KEY
    The private key that Knife will use to sign requests made by the API client to the server.

--[no-]color
    Indicates whether colored output will be used.

--print-after
    Indicates that data will be shown after a destructive operation.

-s URL, --server-url URL
    The URL for the server.

-u USER, --user USER
    The user name used by Knife to sign requests made by the API client to the server. Authentication will fail if the user name does not match the private key.

-V, --verbose
    Set for more verbose outputs. Use -VV for maximum verbosity.

-v, --version
    The version of the chef-client.

-y, --yes
    Indicates that the response to all confirmation prompts will be "Yes" (and that Knife will not ask for confirmation).

-z, --local-mode
    Indicates that the chef-client will be run in local mode, which allows all commands that work against the server to also work against the local chef-repo.

CREATE

The create argument is used to add a data bag to the server.

Syntax

This argument has the following syntax:

$ knife data bag create DATA_BAG_NAME [DATA_BAG_ITEM] (options)

Options

This argument has the following options:

DATA_BAG_ITEM
    The name of a specific item within a data bag.

--secret SECRET
    The encryption key that is used for values contained within a data bag item.

--secret-file FILE
    The path to the file that contains the encryption key.

Note
    For encrypted data bag items, use either --secret or --secret-file, not both.

Examples

To create a data bag named "admins", enter:

$ knife data bag create admins

to return:

Created data_bag[admins]

DELETE

The delete argument is used to delete a data bag or a data bag item from a server.

Syntax

This argument has the following syntax:

$ knife data bag delete DATA_BAG_NAME [DATA_BAG_ITEM] (options)

Options

This argument has the following options:

DATA_BAG_ITEM
    The name of a specific item within a data bag.

    Examples

    $ knife data bag delete data_bag_name

    To delete an item named "charlie", enter:

    $ knife data bag delete admins charlie

    Type Y to confirm a deletion.

EDIT

The edit argument is used to edit the data contained in a data bag. If encryption is being used, the data bag will be decrypted, the data will be made available in the $EDITOR, and then encrypted again before saving it to the server.

Syntax

This argument has the following syntax:

$ knife data bag edit DATA_BAG_NAME [DATA_BAG_ITEM] (options)

Options

This argument has the following options:

DATA_BAG_ITEM
    The name of a specific item within a data bag.

--secret SECRET
    The encryption key that is used for values contained within a data bag item.

--secret-file FILE
    The path to the file that contains the encryption key.

Note
    For encrypted data bag items, use either --secret or --secret-file, not both.

Examples

To edit the contents of a data bag, enter:

$ knife data bag edit admins

To edit an item named "charlie" that is contained in a data bag named "admins", enter:

$ knife data bag edit admins charlie

to open the $EDITOR. Once opened, you can update the data before saving it to the server. For example, by changing:

{
   "id": "charlie"
}

to:

{
   "id": "charlie",
   "uid": 1005,
   "gid":"ops",
   "shell":"/bin/zsh",
   "comment":"Crazy Charlie"
}

FROM FILE

The from file argument is used to create a data bag on the server from a file. The path to the data bag file must specify one of the following:

•   the name of a data bag

•   a relative or absolute path to a file

    If the name of a data bag is specified, Knife will search for the data bag in ./data_bags/bag_name/file. Once opened, the JSON file should be a hash that contains at least an ID key which represents the name of the data bag item.

Warning
    A chef-client must be version 11.6 (or higher) when using the knife data bag from file argument with the Enterprise Chef or Open Source Chef version 11 servers.

Syntax

This argument has the following syntax:

$ knife data bag from file DATA_BAG_NAME_or_PATH

Options

This argument has the following options:

-a, --all
    Indicates that all data bags found at the specified path will be uploaded.

--secret SECRET
    The encryption key that is used for values contained within a data bag item.

--secret-file FILE
    The path to the file that contains the encryption key.

Note
    For encrypted data bag items, use either --secret or --secret-file, not both.

Examples

To create a data bag on the server from a file:

$ knife data bag from file "path to JSON file"

To create a data bag named "devops_data" that contains encrypted data, enter:

$ knife data bag from file devops_data --secret-file "path to decryption file"

LIST

The list argument is used to view a list of data bags that are currently available on the server.

Syntax

This argument has the following syntax:

$ knife data bag list

Options

This argument has the following options:

-w, --with-uri
    Indicates that the corresponding URIs will be shown.

    Examples

    $ knife data bag list

SHOW

The show argument is used to view the contents of a data bag.

Syntax

This argument has the following syntax:

$ knife data bag show DATA_BAG_NAME (options)

Options

This argument has the following options:

DATA_BAG_ITEM
    The name of a specific item within a data bag.

--secret SECRET
    The encryption key that is used for values contained within a data bag item.

--secret-file FILE
    The path to the file that contains the encryption key.

Note
    For encrypted data bag items, use either --secret or --secret-file, not both.

Examples

$ knife data bag show admins

to return something like:

charlie

To show the contents of a specific item within data bag, enter:

$ knife data bag show admins charlie

to return:

comment:  Crazy Charlie
gid:      ops
id:       charlie
shell:    /bin/zsh
uid:      1005

To show the contents of a data bag named "passwords" with an item that contains encrypted data named "mysql", enter:

$ knife data bag show passwords mysql

to return:

## sample:
{
  "id": "mysql",
  "pass": "trywgFA6R70NO28PNhMpGhEvKBZuxouemnbnAUQsUyo=\n",
  "user": "e/p+8WJYVHY9fHcEgAAReg==\n"
}

To show the decrypted contents of the same data bag, enter:

$ knife data bag show --secret-file /path/to/decryption/file passwords mysql

to return:

## sample:
{
   "id": "mysql",
   "pass": "thesecret123",
   "user": "fred"
}

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

$ knife data bag show admins -F json

Other formats available include text, yaml, and pp.

AUTHOR
Chef