kitchen.yml属性不会覆盖默认值

编程入门 行业动态 更新时间:2024-10-17 02:59:21
kitchen.yml属性不会覆盖默认值 - Chef 12.12 - Kitchen 1.10(kitchen.yml attributes not override default values - Chef 12.12 - Kitchen 1.10)

我有一个简单的属性文件: attributes/default.rb 。

default['simpleattr'] = 'file value'

在kitchen.yml里面,我做到了

suites: - name: default run_list: - recipe[simple::default] attributes: simpleattr: 'value from kitchen' simple: simpleattr: 'value from kitchen'

在配方里面,我做:

log "default['simpleattr']: "+node.default['simpleattr']

而且我总是得到'file value'而不是'value from kitchen'作为输出。

我想覆盖测试中的值。

I have a simple attributes file: attributes/default.rb.

default['simpleattr'] = 'file value'

And inside kitchen.yml, I do

suites: - name: default run_list: - recipe[simple::default] attributes: simpleattr: 'value from kitchen' simple: simpleattr: 'value from kitchen'

Inside the recipe, I do :

log "default['simpleattr']: "+node.default['simpleattr']

And I always get 'file value' rather than 'value from kitchen' as output.

I want to override the value in tests.

最满意答案

不要通过node.default[]访问节点值,而是使用node[] 。 Chef的属性层次结构根据其优先级自动计算值。

我已将您的问题转载并在Github上传。 解决方案也如我之前在评论中所述。 不要用

node.default['simpleattr']

但反而

node['simpleattr']

然后一切都如你所料,输出是

Recipe: simple::default * log[default['simpleattr']: value from kitchen] action write

Don't access node values through node.default[], but use node[] instead. Chef's attribute hierarchy automatically calculates the values according to its precedence levels.

I've reproduced your issue and uploaded it here on Github. The solution is as also previously described in my comment. Don't use

node.default['simpleattr']

but instead

node['simpleattr']

Then everything is as you expect and the output is

Recipe: simple::default * log[default['simpleattr']: value from kitchen] action write

更多推荐

本文发布于:2023-07-04 17:07:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1026955.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:默认值   属性   kitchen   yml

发布评论

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

>www.elefans.com

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