Skip to content

Instantly share code, notes, and snippets.

@bastelfreak
Last active July 6, 2020 20:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bastelfreak/b9620fa1892ebcc659c442b115db34f9 to your computer and use it in GitHub Desktop.
Save bastelfreak/b9620fa1892ebcc659c442b115db34f9 to your computer and use it in GitHub Desktop.
class profiles::nfscluster {
# query the puppetdb in an overly complicated way to get the certname of the other cluster member
# this query honours our test/prod environment. it will break as soon as we've three or more nodes in one environment
# https://puppet.com/docs/puppet/5.5/function.html#map
# https://puppet.com/docs/puppet/5.5/function.html#filter
# https://puppet.com/docs/puppetdb/5.1/api/query/v4/ast.html#summary
# https://puppet.com/docs/puppetdb/5.1/api/query/tutorial.html#how-to-query
$nfs_cluster_nodes_query =['from', 'facts', ['and',
['=', 'name', 'hostname'],
['in', 'certname',
['extract', 'certname', ['select_facts',
['and',
['=', ['fact', 'role'], $facts['role']],
['=', ['fact', 'type'], $facts['type']]]]]]]]
$nodes = puppetdb_query($nfs_cluster_nodes_query)
$node = $nodes.map |$node| {
{ 'fqdn' => $node['certname'], 'hostname' => $node['value'] }
}.filter |$node| {
$node['fqdn'] != $trusted['certname']
}[0]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment