In our organization, the devs are being given ownership to own the cookbooks. The cookbooks were initially written by the ops guys. I am a java guy and not a chef/ruby/ops expert. I have been given a task to debug an issue where the cookbook is not reading from the right data-bag.
Is it possible to to list all available data bags on a chef node? I tried something like this but it's taking a long time.
# find / -type f -not -name "*test*" -exec grep -IHnl data_bag {} \; | grep -v gems
The code I am looking at is:
secret2 = Chef::EncryptedDataBagItem.load_secret(secret)
passwords = data_bag_item(id, item, secret2)
When chef-client runs on a node, does it combine all data_bag json files into 1 data structure. While writing the cookbook, do I have to specify which data_bag to load?
Update:
This command ran very quickly after I limited my search to just chef's directories:
# find /run/chef /opt/chef /var/chef /etc/chef -type f -not -name "*test*" -exec grep -IHnl data_bag {} \; | grep -v gems
/var/chef/cache/cookbooks/users/resources/manage.rb
/var/chef/cache/cookbooks/users/CHANGELOG.md
/var/chef/cache/cookbooks/users/metadata.json
/var/chef/cache/cookbooks/users/README.md
/var/chef/cache/cookbooks/xyz_users/recipes/default.rb
/var/chef/cache/cookbooks/xyz_users/attributes/default.rb
/var/chef/cache/cookbooks/xyz_users/README.md
/var/chef/cache/cookbooks/xyz_users/.kitchen.yml
/var/chef/cache/cookbooks/xyz_base/.kitchen.yml
/var/chef/cache/cookbooks/splunk/recipes/mysqlmonitor.rb
/var/chef/cache/cookbooks/splunk/attributes/default.rb
/var/chef/cache/cookbooks/splunk/.kitchen.yml
/var/chef/cache/cookbooks/xyz_service/recipes/config.rb
/var/chef/cache/cookbooks/xyz_service/attributes/default.rb
/var/chef/cache/cookbooks/xyz_service/.kitchen.yml
/var/chef/cache/cookbooks/xyz_service/README.md
/var/chef/cache/cookbooks/xyz_service2/attributes/default.rb
/var/chef/cache/cookbooks/xyz_service2/recipes/certificates.rb
/var/chef/cache/cookbooks/xyz_service2/README.md
/var/chef/cache/cookbooks/xyz_service2/metadata.json
/var/chef/cache/cookbooks/xyz_nginx/.kitchen.yml
Thanks.
as you can see in data bags chef documentation and also you specified that you are looking for the code
so for your question
the answer is yes. refer to the second line in your snippet, which specifies to load a data bag item named
item
from a data bag namedid
and decrept it usingsecret2
key.now to your second question:
from what i know, the answer is no. chef-client fetches a specific data bag from the chef-server on-demand (per what is written in the cookbook).