Skip to content

Instantly share code, notes, and snippets.

@binford2k
Created December 20, 2012 16:56
Show Gist options
  • Save binford2k/4346691 to your computer and use it in GitHub Desktop.
Save binford2k/4346691 to your computer and use it in GitHub Desktop.
a function to abort a class and cause all resource in the class to NOT be applied, without failing compilation like fail()
Puppet::Parser::Functions::newfunction(:failclass, :doc => 'Calling this function will immediately fail the class in current scope and mark all contained resources as failed.') do |args|
raise ArgumentError, ("failclass(): call with a single argument, the message.)") if args.length != 1
# build a resource
p_resource = Puppet::Parser::Resource.new(:whit, args[0], :scope => self, :source => resource)
# then add requirements to all other resources in scope.
# how do i select all resources in current scope?
compiler.catalog.resources.select{ |x| x[:scope] == self }.each do |res|
reqs << Puppet::Relationship::new(p_resource, res)
end
# mark the resource as failed.
p_resource.fail(args[0])
# add to catalog
compiler.add_resource(self, p_resource)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment