Information Technology Reference
In-Depth Information
To create data bag items, use the
knife data_bag from file
command.
knife data_bag
from file
assumes that the
.json
files are in a subdirectory with the specified data bag name
under the directory
data_bags
:
$
knife data_bag from file users alice.json
Updated data_bag_item[users::alice]
$
knife data_bag from file users bob.json
Updated data_bag_item[users::bob]
To search data bags, use the name of the data bag in the
index
parameter to
knife search
.
In this case, our data bag name is users
“:”
. The following command will search for the list
of users we created in a data bag:
$
knife search users "*:*"
2 items found
chef_type: data_bag_item
comment: Alice Jones
data_bag: users
gid: 0
home: /home/alice
id: alice
shell: /bin/bash
uid: 2000
chef_type: data_bag_item
comment: Bob Smith
data_bag: users
gid: 0
home: /home/bob
id: bob
shell: /bin/bash
uid: 2001
You can add specific key-value pairs in the query part of the
knife search
command line.
The following query will return the item where
id == alice
:
$
knife search users "id:alice"
1 items found
chef_type: data_bag_item