Puppet provides an additional mode of operation, that being the discovery of resources using the puppet resource command. The self.instances method should implement the return of any instances of a particular resource type that the provider is able to find on the underlying system.
The following example illustrates the use of the rpm -qa command to query for all packages installed on the underlying Red Hat system:
Puppet::Type.type(:mynewtype).provide(:yum) do ... def self.instances pkgs = rpm('-qa','--qf','%{NAME} %{VERSION}-%{RELEASE}\n') pkgs.split("\n").collect do |entry| name, version = entry.split(' ', 2) new( :name => name, :ensure => :present, :version => version ) end end ... end
Each resource ...