Using the confine method

The confine method can be used with a fact, as shown in the following code:

Puppet::Type.type(:mynewtype).provide(:myprovider) do   ...   confine :osfamily => :redhat   ... end

The confine method could also use exisits to base its conditions on whether a certain file is present on the system under management. The following example demonstrates how the provider is restricted to only those systems where Puppet's .config file exists:

Puppet::Type.type(:mynewtype).provide(:myprovider) do   ...   confine :exisits => Puppet[:config]   ... end

Another possibility is to base the conditions of the confine method on certain Puppet features (they are all listed in the source code directory at https://github.com/puppetlabs/puppet/tree/master/lib/puppet/feature ...

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.