|
Overview
Knife is a command-line tool that comes with Chef.It is used by administrators to interact with the Chef Server API, the local Chef repository and and can be used to manage the arbitrary stores of globally available JSON data known as Data Bags.Knife's data bag sub-command provides this capability.
Managing Data Bags with KnifeData bags can be managed with the knife command line client. Make sure you have correctly configured knife before trying the examples here. Creating Data Bags and ItemsTo create a data bag with knife, use For example, to create a data bag to store data about admins, run this command: Now that the data bag is created, you can put data items in it with knife data bag create BAG[ITEM]. This command will create a skeleton of the JSON for the data bag and drop you into your $EDITOR to edit it. To add an administrator to our admins data bag, we'd do the following: Now, in your editor, you'll see this: To follow along with the example, edit the data bag item as follows: When you exit your editor, knife will save this data to the server. Showing Data Bags and ItemsTo list all of the data bags on the server, use knife data bag list. If you created the admins data bag above, running the command will produce the following result: To view the contents of a data bag, use knife data bag show BAG, for example: To view the contents of a data bag item, use knife data bag show BAG ITEM: Create or Update Data Bag Items from JSONTo create or update a data bag item using a JSON file, use If file is a relative or absolute path to the file, that file will be used. Otherwise, the file parameter is treated as the base name of a data bag file in a Chef repository, and knife will search for the file in ./data_bags/bag_name/file. For example knife data bag from file users dan.json would attempt to load the file ./data_bags/users/dan.json. The JSON file in question should be a Hash that contains at least an "id" key. The "id" key will be the item name. Other keys can be added to this file just as they can when using knife data bag BAG_NAME ITEM_NAME create. Editing Data Bag ItemsData bags are edited via knife with knife data bag edit BAG ITEM. This works similarly to creating data bag items, loading your $EDITOR with the data from the server, and saving it back to the server when you exit the editor. Deleting Data Bags and ItemsTo delete a data bag with knife, use knife data bag delete BAG. Individual data bag items are deleted with knife data bag delete BAG ITEM. Deleting a Data Bag Item Deleting a Data Bag
Encrypted data bags and knifeThe encrypted data bag features of the knife data bag * subcommands are activated by specifying either a --secret or --secret-file option.
Create a new encrypted data bag itemVerify that the data bag has been created and encrypted Decrypt an encrypted data bag itemOther knife encrypted data bag commandsWhen given a --secret or --secret-file option,
|
|
|




