Question

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  "git@github.com/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?

Était-ce utile?

La solution

You can set ignore_failure true

Autres conseils

One possibility is to make your own provider class which subclasses Chef::Provider::Git and change the behavior you don't like in the subclass. You can use the provider attribute method in a resource to set the provider class for that resource - in this case, to your provider class. You will likely place your provider class in a libraries file.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top