Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.