- Mastering Puppet 5
- Ryan Russell Yates Jason Southgate
- 126字
- 2021-07-16 17:46:17
Using the defaultfor method
The confine method is fine, but its usage may still result in multiple valid providers for a particular resource type. In this circumstance, the type should specify its preferred provider using the defaultfor method.
The defaultfor method uses a fact name and value as its arguments, which are then used to determine the default provider for certain types of underlying system.
For example, on Red Hat systems, both yum and rpm would be valid as providers to the package resource type, but the defaultfor method would be used to indicate that for Red Hat systems, yum is in fact the default provider, as shown in the following code:
Puppet::Type.type(:mynewtype).provide(:yum) do
...
confine :osfamily => :redhat
defaultfor: osfamily => :redhat
...
end