简体   繁体   English

有没有一种方法可以为Chef资源的name属性指定默认值?

[英]Is there a way to specify a default value for the name property of a Chef resource?

Ideally, I would like to be able to do: 理想情况下,我希望能够做到:

resource_name :house

property :material, String, default: 'brick', name_property: true
...

so that I could then do 这样我就可以做

house do
  ...
end

and material property would be set to 'brick' , but this results in the error message: 并且material属性将设置为'brick' ,但这会导致错误消息:

A property cannot be both a name_property/name_attribute and have a default value ...

which is clear enough. 这很清楚。 I am reasonably certain what I am asking for is not possible, but, I might also be missing an alternative way of achieving the same, so I thought I would ask. 我可以肯定地确定我所要求的是不可能的,但是,我可能也缺少实现这一目标的另一种方法,所以我想问一下。

No, you would have to do it at the name level itself. 不,您必须在名称级别本身上执行此操作。 See https://github.com/chef/chef/blob/master/lib/chef/resource/apt_update.rb#L31 . 参见https://github.com/chef/chef/blob/master/lib/chef/resource/apt_update.rb#L31

This should be used very very sparingly, it's pretty rare for something to be a true global singleton. 应该非常谨慎地使用它,成为真正的全局单例的情况很少见。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM