2014-03-03 107 views
2

对于给定的用例,我需要通过自定义LWRP更新节点的标签。我试过两种方法:厨师LWRP的更新节点标签

  • 使用'tag'/'untag'。这会产生错误:

    No resource or method named `tag' for ... 
    
  • 使用node[:tags].concat(<new_tags_array>)。这有效,但标签不会保留,所以我不能用它进行搜索。

有什么,我在这里失踪?

感谢

编辑:实际上,问题是:它甚至可以更新节点从一个供应商的属性?

EDIT2:所以这个正确设置标签:

tags = node[:tags] 
tags.concat(new_tags) 
node.override[:tags] = tags 

然而,标签获取每个厨师的客户端运行复位,因此,如果您包括他们之前检查任何这些新的标签的存在(在第二个厨师 - 客户端运行),你不会得到任何标签。

回答

0

我发现问题所在。总结起来:最初的问题是我无法在LWRP的提供者中使用厨师的标签/非标签方法(可能有办法做到这一点,但我没有找到),所以我选择了修改包含所有标签的节点上的'标签'属性。

标签在厨师 - 客户端运行之间持续存在对我来说也很重要。

实现这一目标的方式是根据厨师文档的属性类型设置为normal,这是从来没有复位:

At the beginning of a chef-client run, all default, override, and automatic attributes are reset. The chef-client rebuilds them using data collected by Ohai at the beginning of the chef-client run and by attributes that are defined in cookbooks, roles, and environments. Normal attributes are never reset. All attributes are then merged and applied to the node according to attribute precedence. At the conclusion of the chef-client run, all default, override, and automatic attributes disappear, leaving only a collection of normal attributes that will persist until the next chef-client run.

,这将使其:

tags = node[:tags] 
    tags.concat(new_tags) 
    node.normal[:tags] = tags