Adding the optional ensure property

Although optional, most native Puppet resource types do have an ensure property, although there are exceptions—for example, . exec and notify. You simply give the resource type the ensure property by immediately calling ensurable:

 Puppet::Type.newtype(:mynewtype) do   ensurable   ... end

The corresponding providers for this type would then implement the ensure property through the use of create, exists?, and destroy methods.

In Puppet DSL, the ensure property should be the first attribute in the resource (according to the Puppet style guidelines), and it supports the present and absent keywords (present being the default, so it may be omitted for the sake of brevity), as shown in the following code:

mynewtype ...

Get Mastering Puppet 5 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.