Hi,
Awhile back I did some work around tools to allow overriding a node's
current runlist. While explicit overrides of the run list are now in Chef
proper, implicit overrides are not and were extracted out into a library:
runlist_modifiers[1][2].
This library allows for two features, explicitly setting what recipes are
allowed to run as well as restricting what recipes are allowed to
run. One feature within this implementation to allow expected behavior when
dealing with a restricted recipe is ensuring that other recipes with a
dependency on a restricted recipe are not run. The reason for this
being that when a recipe does an include_recipe, it has an expectation that
resources will be made available from that inclusion, thus if recipe is not
allowed to run then recipes with a dependency on the restricted recipe
should be implicitly restricted from the run list as well.
All of this leads to a very simple "tool" the runlist_modifiers cookbook
provides. If you add the runlist_modifiers as a dependency on your cookbook,
you can then do something like this in your recipe:
unless(some_condition_to_run_recipe)
raise Chef::Exceptions::RestrictedRecipe(self.recipe_name)
end
...
This will not only restrict the recipe from being loaded, but it will unroll
any previously loaded recipes that are dependent on this given recipe.
With your description of your use case, this may not be directly applicable.
Since you state you want to stop a recipe's execution early, it implies that
there may be resources being defined prior to the stop point that you will
want defined regardless. Splitting those bits out into separate recipes would
likely make the runlist_modifiers more applicable. Hope this is at least
some what helpful for another approach that can be taken to accomplish what
you're looking for.
- Chris
[1] http://community.opscode.com/cookbooks/runlist_modifiers
[2] GitHub - hw-cookbooks/runlist_modifiers: Attribute based recipe loading control
Pitucha, Stanislaw Izaak writes:
Hi all,
Is there some official (or at least working) way to stop execution of a
recipe early? (without affecting the rest of the run list)
For example if I have the whole recipe depending on a single switch, I could
just put it inside of:if node[:switch]
....
endbut that would be spanning a couple of screens of code - not the cleanest
solution. Is there a good way to stop execution without throwing an
exception, so that I can do:some_stop_function unless node[:switch]
Regards,
Stanisław Pitucha
Cloud Services
Hewlett Packard