简体   繁体   English

[chef]:查看一个节点上所有可用的数据包

[英][chef]: View all available data bags on a node

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.我是一个 Java 人,而不是厨师/红宝石/操作专家。 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.当chef-client 在节点上运行时,它是否将所有data_bag json 文件组合成1 个数据结构。 While writing the cookbook, do I have to specify which data_bag to load?在编写食谱时,我是否必须指定要加载哪个 data_bag?

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正如您在数据包厨师文档中看到的那样,并且您还指定您正在寻找代码

secret2 = Chef::EncryptedDataBagItem.load_secret(secret)
passwords = data_bag_item(id, item, secret2)

so for your question所以对于你的问题

While writing the cookbook, do I have to specify which data_bag to load?在编写食谱时,我是否必须指定要加载哪个 data_bag?

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 named id and decrept it using secret2 key.参考代码片段中的第二行,它指定从名为id的数据包加载名为item的数据包item ,并使用secret2密钥对其进行secret2

now to your second question:现在回答你的第二个问题:

When chef-client runs on a node, does it combine all data_bag json files into 1 data structure.当chef-client 在节点上运行时,它是否将所有data_bag json 文件组合成1 个数据结构。

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).厨师客户端按需从厨师服务器获取特定数据包(根据食谱中的内容)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM