Question

I'm using the application cookbook recipe to deploy java war files. What I'd like to do is load in the WAR md5 from an external location (in this case our local nexus repository). To load in values from external locations with chef (like run some bash that will output a string to STDOUT and use that value for a chef variable).

Something like this bash:

export CHEF_VARIABLE = `wget -O - $/URL/WHICH/RETURNS/TEXT/STRING`
Was it helpful?

Solution

Use ruby's open-uri. For example, I do this in a cookbook I use for installing VirtualBox. The VirtualBox download site has a text file with checksums (sha256sum).

require 'open-uri'

sha256sum = "" # retrieve the sha256sums from the virtualbox mirror
open("#{node['virtualbox']['urlbase']}/SHA256SUMS").each do |line|
  sha256sum = line.split(" ")[0] if line =~ /#{distfile}/
end

You can view the whole recipe in the source on github. I would probably set that value as an attribute in a recipe outside of the application cookbook's recipes before it in the node's run list.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top