Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@elyscape
Created May 28, 2015 19:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elyscape/ecdabfc7b8fa5e014227 to your computer and use it in GitHub Desktop.
Save elyscape/ecdabfc7b8fa5e014227 to your computer and use it in GitHub Desktop.
lib/puppet/type/remove_after.rb
Puppet::Type.newtype(:remove_after) do
@doc = "Removes ensurable temporary resources once they have been used.
MORE HERE
"
newparam(:temp_resource) do
desc <<-'EOT'
The ensurable resource to remove. This can be specified as either a
resource reference or as a string in the form "Type[name]". Note that
Puppet does not like resource references passed as the namevar unless
wrapped inside a variable.
EOT
isnamevar
def validate(value)
value = Puppet::Resource.new(value) unless value.is_a? Puppet::Resource
unless value.valid_parameter? :ensure
fail Puppet::Error, "Temporary resource #{value.to_s} must be ensurable"
end
super
end
munge do |value|
value.to_s
end
end
def finish
value = parameter(:temp_resource).value.to_s
@temp_resource = @catalog.resource(value)
unless @temp_resource
fail Puppet::ResourceError, "Could not find dependency #{value} for #{ref}"
end
super
end
def refresh
@temp_resource[:ensure] = :absent
@temp_resource.parameter(:ensure).sync
@temp_resource.flush
notice "#{@temp_resource} removed"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment