Using the create and destroy methods

The existence state of a resource is modified with reference to the declaration of the resource with the ensure property by the user in the Puppet DSL by using the create and destroy methods.

The create method is called when both of the following criteria have been met:

  • The ensure property has been set to present in the resource declaration
  • The false value is returned by the exists? method (to indicate that the resource doesn't already exist)

The destroy method is called when both of the following criteria have been met:

  • The ensure property has been set as absent in the resource declaration
  • The true value is returned by the exists? method (to indicate that the resource already exists)

The following code shows how you can use these methods:

Puppet::Type.type(:mynewtype).provide(:yum) do
...
def create
package=resource[:version] ?
“#{resource[:name]}-#{resource[:version]}]” : resource[:name]
yum(‘install', ‘-y, package')
end
...
def destroy
yum(‘erase', ‘-y', resource[:name])
end
...
end

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.147.190