Guards for include_recipe

I’ve got a recipe where I try to download a .deb file but don’t know if the
file really exists on the other side.
If the file is not present I have to build the package from scratch.

I’ve got a recipe which handles the build itself but I’m unable to include/not
include it based on the result of the download attempt.

I can’t use File.exists?() because this is evaluated at compile time and there
the file is not present. For resources I can use guards, but these are not
supported for include_recipe.

How would I handle this scenario and avoid wrapping the build in a bash script
or add my guard to every resource in the build recipe!?

Would something like this work for you?

require "net/http²
url = URI.parse(³http://www.google.com/²)
req = Net::HTTP.new(url.host, url.port)
res = req.request_head(url.path)

include_recipe ³my_stuff² if res.code == ³200"

--
Dang H. Nguyen
Sr. Tools Engineer, Tools & Automation Engineering (formerly Enterprise
Automation Team)
Disney Technology Solutions and Services
925 Fourth Avenue, Suite 1600 | Seattle, WA 98104
(: 206-664-4091
*: dang.nguyen@disney.com

On 10/16/14, 12:21 AM, "felix@psy-coding.com" felix@psy-coding.com wrote:

I've got a recipe where I try to download a .deb file but don't know if
the
file really exists on the other side.
If the file is not present I have to build the package from scratch.

I've got a recipe which handles the build itself but I'm unable to
include/not
include it based on the result of the download attempt.

I can't use File.exists?() because this is evaluated at compile time and
there
the file is not present. For resources I can use guards, but these are not
supported for include_recipe.

How would I handle this scenario and avoid wrapping the build in a bash
script
or add my guard to every resource in the build recipe!?

I already thought about the same way, but this feels somehow to
hacky/not right to me.
I think the right approach would be to convert it to a LWRP, as To
msuggested

Nguyen, Dang mailto:Dang.Nguyen@disney.com
16 Oct 2014 16:52
Would something like this work for you?

require "net/http²
url = URI.parse(³http://www.google.com/²)
req = Net::HTTP.new(url.host, url.port)
res = req.request_head(url.path)

include_recipe ³my_stuff² if res.code == ³200"