2

Is it possible to do the following when querying a data bag to set a node attribute?

I have a series of data bag items that match my local node['fqdn'] attributes.

Is it possible to dynamically insert this attribute into a data bag query string, the below example doesnt work, any other ideas ?

default['test']['attribute'] = Chef::DataBagItem.load('databagname', '<%= node[:platform_version] %>')['test']['bag']['location']
Sathyajith Bhat
  • 21,321
  • 22
  • 95
  • 134
user2163145
  • 21
  • 1
  • 2

1 Answers1

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.

Giannis Nohj
  • 338
  • 2
  • 11