厨师数据袋和动态变量传递 [英] Chef Data Bags and dynamic variable passing

查看:118
本文介绍了厨师数据袋和动态变量传递的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找出一个方法来获得以下代码的工作;我已经尝试过各种方法,但是厨师客户端在第三行运行。

  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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆