2

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

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

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

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

1 回答 1

2

The DataBagItem.load method returns a databag object. So, I usually store the returned databag object into a temp variable and then get the item I want from the databag, like with a a hash. For example:

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

You can replace id with the required element of your databag.

On the other hand, if what you meant was to store the hole databag in a single attribute, I haven't tried it and I don't know if it is possible.

于 2013-03-14T20:56:17.103 回答