如何在厨师食谱中提供条件以查看其是否在测试厨房中运行? [英] How to provide a condition within Chef recipe to see if it running under test kitchen?
本文介绍了如何在厨师食谱中提供条件以查看其是否在测试厨房中运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在Chef内使用加密的数据包,并且想在我的Chef食谱中添加一个条件,如下所示:
I am using encrypted data bags within Chef and I want to add a condition within my Chef recipe as follows:
If (test kitchen) then
encryptkey = data_bag_item("tokens", "encryptkey")
If ( not test kitchen ) then
secret = Chef::EncryptedDataBagItem.load_secret("/etc/chef/encrypted_data_bag_secret")
encryptkey = Chef::EncryptedDataBagItem.load("tokens", "encryptkey", secret)
我在厨房中添加了
如下: data_bags_path
和 encrypted_data_bag_secret_key_path
.yml
I have added data_bags_path
and encrypted_data_bag_secret_key_path
within kitchen.yml
as follows:
provisioner:
name: chef_zero
chef_omnibus_url: omni-url/chef/install.sh
roles_path: 'test/integration/default/roles'
data_bags_path: "test/integration/default/data_bags"
encrypted_data_bag_secret_key_path: "test/integration/default/encrypted_data_bag_secret"
推荐答案
使用
suites:
- name: default
data_bags_path: 'databags'
run_list:
- recipe[x::y]
attributes: {'kitchen' : 'true' }
如果条件使用node ['chef-mode']的值放在您的配方内。
Inside your recipe put if condition using the value of node['chef-mode'].
if node['kitchen'] == 'true'
#something
else
#else
end
这篇关于如何在厨师食谱中提供条件以查看其是否在测试厨房中运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文