Exported resources
An exported resource declaration specifies a desired state for a resource, and publishes the resource for use by other nodes. It does not manage the resource on the target system. Any node, including the node that exports it, can collect the exported resource and manage its own copy of it.
Purpose
Exported resources enable the Puppet compiler to share information among nodes by combining information from multiple nodes’ catalogs. This helps manage things that rely on nodes knowing the states or activity of other nodes.
nagios_service
resource which describes how to monitor the service, including information
such as its hostname and port. The Nagios server collects every nagios_service
resource, and
automatically starts monitoring the Postgres server.storeconfigs
) enabled on your Puppet master. Both the catalog storage and the
searchin, among other features, are provided by PuppetDB. To enable exported resources, see:
Syntax
Using exported resources requires two steps: declaring and
collecting. In the following examples, every node with the ssh
class exports its own
SSH host key and then collects the SSH host key of every node (including its own).
This causes every node in the site to trust SSH connections from every other
node.
class ssh {
# Declare:
@@sshkey { $::hostname:
type => dsa,
key => $::sshdsakey,
}
# Collect:
Sshkey <<| |>>
}
@@
to the resource
type of a standard resource
declaration:@@nagios_service { "check_zfs${::hostname}":
use => 'generic-service',
host_name => $::fqdn,
check_command => 'check_nrpe_1arg!check_zfs',
service_description => "check_zfs${::hostname}",
target => '/etc/nagios3/conf.d/nagios_service.cfg',
notify => Service[$nagios::params::nagios_service],
}
nagios_service
resources:Nagios_service <<| |>>
This
example, taken from puppetlabs-bacula, uses the concat module, collects exported file fragments for building a
Bacula config file:Concat::Fragment <<| tag == "bacula-storage-dir-${bacula_director}" |>>
For more information on the collector syntax and search expressions, see Exported Resource Collectors.
Behavior
When catalog storage and searching (storeconfigs
) are enabled, the master
sends a copy of every compiled catalog to PuppetDB.
PuppetDB retains the recent catalog for every node and provides the master with a
search interface to each catalog.
Declaring an exported resource adds the resource to the catalog marked with an exported flag. Unless it was collected, this prevents the agent from managing the resource. When PuppetDB receives the catalog, it takes note of this flag.
Collecting an exported resource causes the master to send a search query to PuppetDB. PuppetDB responds with every exported resource that matches the search expression, and the master adds those resources to the catalog.
An exported resource becomes available to other nodes as soon as PuppetDB finishes storing the catalog that contains it. This is a multi-step process and might not happen immediately. The master must have compiled a given node’s catalog at least once before its resources become available. When the master submits a catalog to PuppetDB, it is added to a queue and stored as soon as possible. Depending on the PuppetDB server’s workload, there might be a delay between a node’s catalog being compiled and its resources becoming available.
hostname
or fqdn
facts.For example, to create a class for Apache that adds a service definition on your Nagios host, automatically monitoring the web server:
/etc/puppetlabs/puppet/modules/nagios/manifests/target/apache.pp
:class nagios::target::apache {
@@nagios_host { $::fqdn:
ensure => present,
alias => $::hostname,
address => $::ipaddress,
use => 'generic-host',
}
@@nagios_service { "check_ping_${::hostname}":
check_command => 'check_ping!100.0,20%!500.0,60%',
use => 'generic-service',
host_name => $::fqdn,
notification_period => '24x7',
service_description => "${::hostname}_check_ping"
}
}
/etc/puppetlabs/puppet/modules/nagios/manifests/monitor.pp
:class nagios::monitor {
package { [ 'nagios', 'nagios-plugins' ]: ensure => installed, }
service { 'nagios':
ensure => running,
enable => true,
#subscribe => File[$nagios_cfgdir],
require => Package['nagios'],
}
Collect
resources and populate /etc/nagios/nagios_*.cfg
: Nagios_host <<||>>
Nagios_service <<||>>
}