0

Is there a way to communicate information between classes/resources?

I have a profile that I want to include on all nodes to set them up as being monitored by Icinga which uses an exported resource :

class profile::icinga2::host {
  @@::icinga2::object::host { $::fqdn:
      display_name     => $::fqdn,
      address          => $::ipaddress,
      vars             => hiera_hash('icinga_vars',{}) + {
         "dns_lookup" => $::fqdn,
         "dns_expected_answers" => $::ipaddress,
      },
      target           => "/etc/icinga2/conf.d/puppet.d/${::fqdn}.conf"
  }
}

These resources are then declared in the icinga server using the resource collector:

<<| icinga2::object::host|>>

I want to be able to customize the vars entry in the profile::icinga2::host resource and at the moment doing by adding icinga_vars data into the hiera yaml file for the node e.g.:

icinga_vars:
    http_uri: "http://puppetboard.zoo.lan" 

However ideally I would do this inside any classes that are included by the node itself.

Is there a way of setting up data in classes that can then be read by a different class?

Facts don’t seem the right way of doing it and nor does puppetdb, is there an alternative?

Can I, for example, create a icinga2::variable class and declare those outside the profile::icinga2::host class and then iterate over them in the profile::icinga2::host class? How would that be done and how would dependencies be handled e.g. I would need to ensure the icinga2::variables are ready to be read by profile::icinga2::host Thanks

Phil
  • 3,138
  • 1
  • 21
  • 27
  • I must be missing something here, why wouldn't you do this in hiera? Then the variables will be available to all classes with a lookup. – jdopenvpn Jan 16 '21 at 23:36
  • the data to be added is resource specific not host specific hence why I want to put it into a resource. – Phil Jan 18 '21 at 11:31
  • If it is added to common.yaml it will be available for all resources – jdopenvpn Jan 18 '21 at 12:35

0 Answers0