Using the GET and SET methods to manage type properties

Each property defined in the type should implement a GET and SET method in the provider.

Puppet will then invoke these methods during a Puppet run to manage the property as follows:

  1. The GET method is called initially to retrieve the current value
  2. This is subsequently compared against the value declared by the user in the Puppet DSL
  3. If the values are different, then the SET method is invoked to update that value if necessary.

This is shown in the following code:

Puppet::Type.type(:mynewtype).provide(:yum) do   ...   def version     version = rpm('-q', resource[:name])     if version =~ /^#{Regexp.escape(resource[:name])}-(.*)/       $1     end   end    def version=(value) yum('install', "#{resource[:name]}-#{resource[:version]}") ...

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.