我有一个简单的属性文件: 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 writeDon'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更多推荐
发布评论