Created
May 28, 2015 19:38
-
-
Save elyscape/ecdabfc7b8fa5e014227 to your computer and use it in GitHub Desktop.
lib/puppet/type/remove_after.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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