How to make an extra resource for a chef extra?

I have a resource in a chef's recipe that I would like to be extra. That is, when the recipe starts, if the resource does not work, I want everything else to keep going. Anyway, I would like to know that, of course, there was a failure with this resource, it just is not a critical resource and nothing depends on it, so I would prefer that the rest of the work go on.

I'm used to working with Puppet, where you must explicitly declare your dependencies, and resources are skipped only when they freeze, instead of a single failure, which is why the rest of the file does not start.

Not sure why this was closed, since it is not a question (even after reading the FAQ), but I will add sample code to illustrate what I ask, I hope someone else can vote to open or answer again.

I use a chef to set up the dev environment, and part of it just clones some git repositories. Nothing depends on them, and sometimes there is a private repo to which some developers do not have access. If he will not clone, I would like other resources to continue to be executed.

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 doing this does not have the right to clone foo, I would like foo to fail, but bar and baz are still cloned. How is this possible?

+7
source share
2 answers

You can set ignore_failure true

+6
source

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

0
source

All Articles