0
votes

I have a group of packages that would be nice to add to a data bag in order to install them all. Is it possible to use the package resource with a data bag?

EDIT: For instance - this is how I'm doing it with the chocolatey resource:

workstation_apps = data_bag_item('winapps','desktop_apps')

chocolatey_package workstation_apps['apps']

This is the data bag structure:

{
  "id": "desktop_apps",
  "apps": [
   "slack",
   "putty",
   "jre8",
   "python2",
   "ruby",
   "chefdk",
   "vmwarevsphereclient",
   "vmwareworkstation",
   "vagrant",
   "terraform",
   "packer",
   "visualstudiocode",
   "pushbullet",
 ]
}

This works with the "chocolatey" resource - but will it work with the standard package resource on linux (yum)?

2
Please add your code, at least as far as you got with that issue. - StephenKing

2 Answers

0
votes

Yes, it is possible - it's all just code.

You can extract such information from a data bag and pass the list of package names as list to the package resource.

0
votes

You aren't really passing the package resource here "a data bag" you're passing it an Array which you've pulled out of a data_bag. The package provider doesn't know anything about the data_bag that you're using.

What you're doing is no different than chocolatey_package [ "slack", "putty" .... ]. To do versions you need to pass it an identical length array of versions:

package [ "slack", "putty", "jre8" ] do
  version [ nil, "1.2.3", nil ]
end

You should probably store that as name, version pairs in a hash in a databag, and then extract keys and values as arrays. to give to the package provider.