A DATABAG is a GLOBAL variable stored in JSON – Java Script Object Notation.

Type of data, e.g.:

User Account information

Sudo users

API / Database schema Credentials

etc

Can be encrypted

e.g. users on a system, sudo users, API/DB Credentials etc
{
“id”:”PHH”,
“comment”:”Another User”,
“uid”:”1000″,
“home”:”/home/oracle”,
“shell”,”/bin/bash”
}
Set up data_bags directories for our users and our groups data_bags
$ cd chef-repo
$ mkdir data_bags
$ cd data_bags

$ mkdir {users,groups}

Set up the wheel sudoers group

$ cd ../groups
$ vi sudoers.json
{
“id”:”wheel”,
“gid”:”1000″,
“members”:[“phh”]
}
 
Set up the users data_bag for user phh
$ cd users
$ vi phh.json
{
“id”:”phh”,
“comment”:”Another User”,
“uid”:”10″,
“gid”:”1000″,
“home”:”/home/oracle”,
“shell”,”/bin/bash”,
“password”:”mypwd”
}
 
Create the data_bag items
$ knife data bag create users
Created data_bag[users]
 
$ knife data bag create groups
Created data_bag[groups]
Go to the WEB and look at the data_bags
-> Policy -> databags
Add the data_bag items
$cd ..
$ knife data_bag from file users phh.json
$ knife data_bag from file groups sudoers.json

Search groups

$ knife search users “id:phh”
1 item found
chef_type: data_bag_item
:
etc
 
$ knife search users “id:phh” -a home
1 item found
chef_type: data_bag_item
:
home:   /home/admin
:
 
etc
 
SAME as normal search