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 primary Puppet server. Both the catalog storage and the searching,
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 => $::facts['networking']['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, which uses the puppetlabs-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 primary server sends a copy of every compiled catalog to PuppetDB. PuppetDB retains the recent catalog for every node and provides
the server 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 primary server to send a search query to PuppetDB. PuppetDB responds with every exported resource that matches the search expression, and the server 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 primary server must have compiled a given node’s catalog at least one time before its resources become available. When the primary server 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.
Normally, exported resource types include their default attribute values. However, defined types are evaluated for the catalog after the resource is collected, so their default values are not exported. To make sure a defined type's values are exported, set them explicitly.
To remove stale exported resources, expire or deactive the node that exported them. This ensures that any resources exported by that node stop appearing in the catalogs served to the remaining agent nodes. For details, see the documentation for deactivating or expiring nodes.
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 { $::facts['networking']['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 => $::facts['networking']['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 <<||>>