Puppet Function: get_clusters

Defined in:
modules/wmflib/lib/puppet/parser/functions/get_clusters.rb
Function type:
Ruby 3.x API

Overview

get_clusters()Any

Returns:

  • (Any)


24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'modules/wmflib/lib/puppet/parser/functions/get_clusters.rb', line 24

newfunction(:get_clusters, :type => :rvalue) do |args|
  all = {}
  # Hiera is the source of truth about clusters/site
  cluster_config = call_function(:hiera, ['wikimedia_clusters', {}])

  # Arguments are an hash of selectors
  selector ||= {}
  selector = args[0] unless args.empty?
  if selector.include? 'cluster'
    clusters = selector['cluster']
  else
    clusters = cluster_config.keys
  end

  if selector.include? 'site'
    sites = selector['site']
  else
    sites = false
  end

  function_query_resources([false, 'Class["Cumin::Selector"]', false])
    .sort_by{ |n| n['certname'] }.each do |node|
    cluster = node['parameters']['cluster']
    site = node['parameters']['site']
    fqdn = node['certname']
    next unless clusters.include?cluster
    next if sites && !sites.include?(site)
    all[cluster] ||= {}
    all[cluster][site] ||= []
    all[cluster][site] << fqdn
  end
  all
end