Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you make a chef resource optional?

I've got a resource in a chef recipe that I'd like to be optional. That is, when the recipe runs, if the resource fails I want everything else to keep going. I'd still like to know there was a failure with that resource of course, it's just that it's not a critical resource and nothing depends on it, so I'd rather the rest of the run continue.

I'm used to working with Puppet where you have to explicitly declare your dependencies, and resources are skipped only when they're dependencies fail instead of one failure causing the whole rest of the file not to run.

Not sure why this was closed as not a real question (even after reading the FAQ), but I'll add some example code to illustrate what I'm asking, hopefully someone else can vote to reopen or can answer.

I'm using chef to setup a dev environment, and part of that is just cloning some git repos to have in place. Nothing depends on them, and occasionally there's a private repo that some devs don't have access to. If it fails to clone, I'd like the other resources to continue being run.

So for the following resources:

["foo", "bar", "baz"].each do |repo|
  git repo do
    repository  "[email protected]/example/#{repo}"
    reference   "master"
    action      :sync
    depth       1
    user        'dev'
    group       'dev'
    destination "#{node[:src_dir]}/#{repo}"
  end
end

If the user running this doesn't have permission to clone foo, I'd like foo to fail, but bar and baz to still clone. How is that possible?

like image 910
mmrobins Avatar asked Nov 01 '12 23:11

mmrobins


1 Answers

You can set ignore_failure true

like image 126
Mark Amerine Turner Avatar answered Sep 28 '22 05:09

Mark Amerine Turner