厨师数据袋和动态变量传递 [英] Chef Data Bags and dynamic variable passing
问题描述
lsf =#{node [:env ]}+_ ls
dsf =#{node [:env]}+_ ds
dsTemplateBag = data_bag_item('configTemplates',#{dsf})
lcTemplateBag = data_bag_item('configTemplates',#{lsf})
另一个测试食谱我能够成功地得到以下工作:
env =test
dsTemplateBag = data_bag_item('configTemplates',#{env})
请问有人可以告诉我如何使这个工作吗?
经过一点调试,我意识到有一个防止错字数据包要正确使用;因此发行。
dsTemplateBag = data_bag_item('configTemplates',#{node [:env]} _ ls)
这对我有用。而如同Tensibai在上述评论中建议的,混合连接和插值不是一个很好的做法(我绝望地使它工作!在我的防御)。
I am trying to figure out a way to get the below code work; I have tried various methods but the chef-client run breaks at the 3rd line.
lsf = "#{node[:env]}"+"_ls"
dsf = "#{node[:env]}"+"_ds"
dsTemplateBag = data_bag_item('configTemplates', "#{dsf}")
lcTemplateBag = data_bag_item('configTemplates', "#{lsf}")
However on another test recipe I was able to successfully get the following working:
env = "test"
dsTemplateBag = data_bag_item('configTemplates', "#{env}")
I am quite new to Chef and please can someone advise me on how to get this working ?
After a little bit debugging I realised there was a typo preventing the data bag to be properly used; hence issue.
dsTemplateBag = data_bag_item('configTemplates', "#{node[:env]}_ls")
this worked for me. And as Tensibai suggested in the above comment mixing concatenation and interpolation is not a good practice (I was desperate to make it work! In my defense).
这篇关于厨师数据袋和动态变量传递的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!