The type API expresses resources that can be leveraged from Puppet’s DSL to manage the underlying system. In fact, all native resource types that ship as a part of Puppet (packages, users, files, services, …) are implemented using the type API covered in this chapter. In addition, the type API specifies the attributes for describing each resource. For example:
This API offers developers a simple collection of Ruby methods to create resource interfaces that serve as an abstraction layer on which multiple providers can be implemented. It also allows sysadmins to describe system configuration as resources without understanding the procedures developers have implemented via providers.
This section will focus on how custom types are written in Ruby, and will cover the following:
Resource types are defined by calling the
newtype method on the
Puppet::Type class and passing it a symbol representing the name of the type to create.
In Ruby, symbols are constructed by placing a colon before a string (i.e.,
:"hello"). Symbols are often used instead of strings in Ruby for performance reasons because symbols, unlike strings, refer to a unique object. Because of this, symbols ...