厨师数据袋和动态变量传递

编程入门 行业动态 更新时间:2024-10-24 20:13:05
本文介绍了厨师数据袋和动态变量传递的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我试图找出一个方法来获得以下代码的工作;我已经尝试过各种方法,但是厨师客户端在第三行运行。

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).

更多推荐

厨师数据袋和动态变量传递

本文发布于:2023-11-06 21:41:49,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1564750.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:厨师   变量   动态   数据

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!