Version information
This version is compatible with:
- Puppet Enterprise 2023.2.x, 2023.1.x, 2023.0.x, 2021.7.x, 2021.6.x, 2021.5.x, 2021.4.x, 2021.3.x, 2021.2.x, 2021.1.x, 2021.0.x, 2019.8.x
- Puppet >= 6.21.0 < 8.0.0
- CentOS, OracleLinux, RedHat, Scientific, Debian, Ubuntu, Fedora, Darwin, SLES, Solaris, windows, AIX
Start using this module
Add this module to your Puppetfile:
mod 'southalc-peers', '0.1.0'
Learn more about managing modules with a PuppetfileDocumentation
peers
Table of Contents
Description
This module includes functions to obtain an array of nodes with puppet resources that match specific criteria. This is useful for things like getting a dynamic list of nodes that are cluster members. The module does not use exported resources, although puppetdb is required.
Setup
Deploying the module to an environment should be all that is necessary to use the included functions. The module does not manage any resources.
Usage
The following example uses the 'peers::resource_by_param' function in a manifest to get an array of nodes that have the 'elasticsearch' class assigned with the 'config.cluster.name' parameter set to 'cluster-1'. Based on the returned array you can do things like check if the current node is already a member, join the cluster, adjust the value for quorum, and update seed hosts.
$elk_servers = peers::resource_by_param('elasticsearch', 'config.cluster.name', 'cluster-1')
The functions default to the node's environment, but this can be overridden by passing another parameter to the function. To repeat the last Elasticsearch query, but in the "test" environment:
$elk_servers = peers::resource_by_param('elasticsearch', 'config.cluster.name', 'cluster-1', 'test')
The other module functions enable searching for nodes based on different criteria. See the module reference for details, but here's another example to get nodes with the 'elasticsearch' module assigned, this time matching nodes based on the trusted fact extension 'pp_cluster' set to the value of 'cluster-01':
$elk_servers = peers::resource_by_tx('elasticsearch', 'pp_cluster', 'cluster-01')
Besides direct configuration of the Elasticsearch cluster, the array of cluster nodes could be useful to setup a kibana resource:
$elk_servers = peers::resource_by_param('elasticsearch', 'config.cluster.name', 'cluster-1')
class { 'kibana':
config => {
'server.host' => fact('networking.ip'),
'elasticsearch.hosts' => $elk_servers.map |$node| { "http://${node}:9200" },
},
}
Limitations
The module uses a fairly basic puppetdb query and should work with all supported Puppet distributions where puppetdb is included.
Development
I'd appreciate any feedback. To contribute to development, fork the source and submit a pull request.
Reference
Table of Contents
Functions
peers::resource_by_fact
: Return an array of nodes by certname that have a resource matching the given class, fact value, and environment.peers::resource_by_param
: Return an array of nodes by certname that have a resource matching the given class, parameter value, and environment.peers::resource_by_param_w_fact
: Return a hash of certnames mapped to fact values when the node has a resource matchingpeers::resource_by_tag
: Return an array of nodes by certname that have a resource matching the given class, tag, and environment.peers::resource_by_tx
: Return an array of nodes by certname that have a resource matching the given class, trusted extension value, and environment.
Functions
peers::resource_by_fact
Type: Puppet Language
Return an array of nodes by certname that have a resource matching the given class, fact value, and environment.
Examples
Get an array of nodes with the 'elasticsearch' class assigned that have the value
of 'cluster-01' assigned as the fact named 'cluster':
$elk_servers = peers::resource_by_fact('elasticsearch', 'cluster', 'cluster-01')
peers::resource_by_fact(String $class, String $fact, String $value, String $env = $server_facts['environment'])
The peers::resource_by_fact function.
Returns: Array
certnames that match function parameters
Examples
Get an array of nodes with the 'elasticsearch' class assigned that have the value
of 'cluster-01' assigned as the fact named 'cluster':
$elk_servers = peers::resource_by_fact('elasticsearch', 'cluster', 'cluster-01')
class
Data type: String
The class name associated with the resource.
fact
Data type: String
The fact name from the node with the resource.
value
Data type: String
The value of the given fact for the node.
env
Data type: String
An optional environment to search for matching resources. Defaults to the node environment.
peers::resource_by_param
Type: Puppet Language
Return an array of nodes by certname that have a resource matching the given class, parameter value, and environment.
Examples
Get an array of nodes with the 'elasticsearch' class assigned that have the value
of 'cluster-01' assigned as the class parameter 'config.cluster.name':
$elk_servers = peers::resource_by_param('elasticsearch', 'config.cluster.name', 'cluster-01')
peers::resource_by_param(String $class, String $parameter, String $value, String $env = $server_facts['environment'])
The peers::resource_by_param function.
Returns: Array
certnames that match function parameters
Examples
Get an array of nodes with the 'elasticsearch' class assigned that have the value
of 'cluster-01' assigned as the class parameter 'config.cluster.name':
$elk_servers = peers::resource_by_param('elasticsearch', 'config.cluster.name', 'cluster-01')
class
Data type: String
The class name associated with the resource.
parameter
Data type: String
The parameter name associated with the resource.
value
Data type: String
The value of the given parameter associated with the resource.
env
Data type: String
An optional environment to search for matching resources. Defaults to the node environment.
peers::resource_by_param_w_fact
Type: Puppet Language
the given class, parameter value, fact name, and environment.
Examples
Get a hash where the keys are nodes with the 'elasticsearch' class assigned that have the value
of 'cluster-01' assigned as the class parameter 'config.cluster.name', and the hash values are from the
custom fact 'node_cert_serial':
$elk_servers = peers::resource_by_param('elasticsearch', 'config.cluster.name', 'cluster-01', 'node_cert_serial')
peers::resource_by_param_w_fact(String $class, String $parameter, String $value, String $fact, String $env = $server_facts['environment'])
the given class, parameter value, fact name, and environment.
Returns: Hash
Hash keys are certnames with values set to value of the given fact for the node.
Examples
Get a hash where the keys are nodes with the 'elasticsearch' class assigned that have the value
of 'cluster-01' assigned as the class parameter 'config.cluster.name', and the hash values are from the
custom fact 'node_cert_serial':
$elk_servers = peers::resource_by_param('elasticsearch', 'config.cluster.name', 'cluster-01', 'node_cert_serial')
class
Data type: String
The class name associated with the resource.
parameter
Data type: String
The parameter name associated with the resource.
value
Data type: String
The value of the given parameter associated with the resource.
fact
Data type: String
The name of some fact where the value will be paired with the certname in the returned hash.
env
Data type: String
An optional environment to search for matching resources. Defaults to the node environment.
peers::resource_by_tag
Type: Puppet Language
Return an array of nodes by certname that have a resource matching the given class, tag, and environment.
peers::resource_by_tag(String $class, String $tag, String $env = $server_facts['environment'])
The peers::resource_by_tag function.
Returns: Array
certnames that match function parameters
class
Data type: String
The class name associated with the resource.
tag
Data type: String
The value of a tag associated with the resource.
env
Data type: String
An optional environment to search for matching resources. Defaults to the node environment.
peers::resource_by_tx
Type: Puppet Language
Return an array of nodes by certname that have a resource matching the given class, trusted extension value, and environment.
Examples
Get an array of nodes with the 'elasticsearch' class assigned that have the value
of 'cluster-01' assigned as the trusted fact extension 'pp_cluster':
$elk_servers = peers::resource_by_tx('elasticsearch', 'pp_cluster', 'cluster-01')
peers::resource_by_tx(String $class, String $trusted_fact, String $value, String $env = $server_facts['environment'])
The peers::resource_by_tx function.
Returns: Array
certnames that match function parameters
Examples
Get an array of nodes with the 'elasticsearch' class assigned that have the value
of 'cluster-01' assigned as the trusted fact extension 'pp_cluster':
$elk_servers = peers::resource_by_tx('elasticsearch', 'pp_cluster', 'cluster-01')
class
Data type: String
The class name associated with the resource.
trusted_fact
Data type: String
The name of the trusted fact extension to match.
value
Data type: String
The value of the trusted fact extension to match.
env
Data type: String
An optional environment to search for matching resources. Defaults to the node environment.
Dependencies
- puppetlabs/stdlib (>= 4.1.0 <= 9.0.0)