【问题标题】:Chef - Data Bag QueryChef - 数据包查询
【发布时间】:2013-02-28 18:38:29
【问题描述】:

在查询数据包设置节点属性时,是否可以做如下操作?

我有一系列与我的本地节点['fqdn'] 属性匹配的数据包项。

是否可以将此属性动态插入到数据包查询字符串中,下面的示例不起作用,还有其他想法吗?

default['test']['attribute'] = Chef::DataBagItem.load('databagname', '<%= node[:platform_version] %>')['test']['bag']['location']

【问题讨论】:

    标签: chef-infra databags


    【解决方案1】:

    DataBagItem.load 方法返回一个数据包对象。所以,我通常将返回的数据包对象存储到一个临时变量中,然后从数据包中获取我想要的项目,就像一个哈希一样。例如:

    temp = Chef::DataBagItem.load('databagname', node.platform_version)
    node.default['test']['attribute'] = temp['id'] 
    

    您可以将 id 替换为数据包所需的元素。

    另一方面,如果您的意思是将洞数据包存储在单个属性中,我没有尝试过,不知道是否可行。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多