Thank you. I was expecting something like that :-/ Your described process 
is in general what we are doing with all of our custom providers. 

Unfortunately, in this case, we have something "special". The provider does 
not manage anything which can be accessed locally from the system. 
The provider subscribes and unsubscribes yum repo channels through a remote 
xmlrpc interface. To do this we need a username and password, this is part 
of the defined resource and comes from hiera. This is fine for creating the 
resources since we have all parameters available in the "create" method.

But to get the list of applied resources  we are using a method within the 
"instances" method, that pulls the list of actually subscribed channels. 
This methods need the authentication information as well, but in this phase 
of the provider we do not have access to the parameters of the defined 
resources, right?

Here's the code within the instances method. The "getSubscribedChannels" 
method would need username and password from hiera / provided through the 
type. Right now it is hardcoded within the "getSubscribedChannels" method 
itself.

  def self.instances
    resources = []
    begin
      @subscribed_channels = getSubscribedChannels(client)
    rescue Puppet::ExecutionFailure => e
      Puppet.debug "Error while fetching subscribed channels -> 
#{e.inspect}"
      return {}
    end
    @subscribed_channels.each do |channel|
        resources.push(new(
          :name => channel,
          :ensure => :present,
         ))
    end
    resources
  end

Is there an alternative way to do this?
On Monday, 1 August 2022 at 21:08:16 UTC+2 ben....@puppet.com wrote:

> Not directly. Hiera provides data to the server for use when compiling the 
> catalog. Providers run on the agent after the catalog has been compiled.
>
> If you need to get to Hiera data, write your type/provider such that it 
> accepts a parameter, then look that up from Hiera and pass it in when you 
> declare a resource.
>
> On Mon, Aug 1, 2022 at 12:06 PM Matthias K <matthi...@gmail.com> wrote:
>
>> Hi, is it possible to access hiera values within a custom provider?
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Puppet Users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to puppet-users...@googlegroups.com.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/puppet-users/7b664134-0ed6-44d8-8054-b48f8de4e578n%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/puppet-users/7b664134-0ed6-44d8-8054-b48f8de4e578n%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to puppet-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/7ca993f6-e437-4741-9433-0ba9da572bcen%40googlegroups.com.

Reply via email to