$ cd chef-repo/cookbooks
$ knife cookbook create addusers
$ cd addusers
$ cd recipes
# remember each data_bag must have a unique id attribute
$ vi default.rb
# Seach the data_bag users for all users
search(:users, “*:*”).each do |data|
user data[“id”] do
comment data[“comment”]
uid data[“guid”]
gid  data[“gid”]
home data[“home”]
shell data[“shell”]
end
end
 
$ knife cookbook upload addusers
 
$ knife node run_list add ” recipe[addusers]”
cc:
run_list:
recipe[secdel]
recipe[apache]
recipe[addusers]
CLIENT
$ chef-client
We can now see that the phh user hasd been added to the system.

Groups

$ vi groups.rb
# Seach the data_bag users for all users
search(:groups, “*:*”).each do |data|
group data[“id”] do
gid data[“gid”]
members  data[“members”]
home data[“home”]
shell data[“shell”]
end
end
 
$ vi default.rb
ADD at the end:
include_recipe “addusers::groups”
$ knife cookbook upload addusers
 
run the cghef-client on the client again and we will see the group has been added.
 
NOW ADD the defult user USER to the group
cd chef-repo/data_bags/groups
vi groups.json
change
members”: [“phh”]
TO
members”: [“phh”, “USER”]
 
$knife data_bag from file groups groups.json
 
NOW chef-client will amend the users WITHOUT having to change any recipes.