O'Reilly logo

Puppet Types and Providers by Nan Liu, Dan Bode

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 3. Providers

Providers implement the actions used to manage resources on a system. Where types express the interfaces used to describe resources, providers implement how resources interact with the underlying system. This clear separation between the interface and the implementation allows multiple providers to be specified for each type. The native type package, for example, has separate providers that can interact with package utilities across a large number of Linux systems, including apt, yum, rpm, and zypper.

In the last chapter, we created a type called custom_package, along with a list of attributes describing the resource. This type can be used to express packages that Puppet manages, like the following example:

custom_package { 'httpd':
  ensure  => present,
  version => '1.2.3-5',
}

This chapter will demonstrate how to implement multiple providers for our custom_package type and covers the following:

  • How to create a custom provider and associate it with a type
  • How Puppet determines the most appropriate provider
  • How providers manage resource state
  • How providers query for a list of all instances
  • Provider optimizations

Creating a Provider

Because providers manage the system state described by a resource type, you must first retrieve the instance of a type associated with the provider. The type method can be called on Puppet::Type to access any instance of either a native or custom type that Puppet knows about.

Note

Many of the examples in this chapter will use irb to interact ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required