Puppet Function: wmflib::resource::hosts

Defined in:
modules/wmflib/functions/resource/hosts.pp
Function type:
Puppet Language

Summary

function to return a list of hosts running a specific resource This function relies on data being present in puppetdb. This means that new nodes will be returned after their first successful puppet run using the specified resource. It also means that nodes will be removed from the results once they have been purged from puppetdb. This currently happens when a server has failed to run puppet for 14 days

Overview

wmflib::resource::hosts(Wmflib::Resource::Type $resource, Variant[Wmflib::Sites, Array[Wmflib::Sites]] $location = [], Optional[String[1]] $resource_title = undef)Array[Stdlib::Host]

Parameters:

  • resource (Wmflib::Resource::Type)

    the resource to search for

  • optional

    list of sites if present filter to output based on the sites passed

  • resource_title (Optional[String[1]]) (defaults to: undef)

    the resource title to search for

  • location (Variant[Wmflib::Sites, Array[Wmflib::Sites]]) (defaults to: [])

Returns:

  • (Array[Stdlib::Host])


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'modules/wmflib/functions/resource/hosts.pp', line 9

function wmflib::resource::hosts (
    Wmflib::Resource::Type                       $resource,
    Variant[Wmflib::Sites, Array[Wmflib::Sites]] $location       = [],
    Optional[String[1]]                          $resource_title = undef,
) >> Array[Stdlib::Host] {

    $_resource = wmflib::resource::capitalize($resource)
    $_title = $resource_title ? {
        undef   => '',
        default => " and title = \"${resource_title}\"",
    }

    # TODO: need a better way to determine site
    # this doesn't work for wikimedia.org domains
    $_location = Array($location, true)
    $site_constraint = $_location.empty ? {
        true    => '',
        default => " and certname ~ \"${_location.join('|')}\"",
    }
    $pql = @("PQL")
    resources[certname] {
        type = "${_resource}" ${_title}${site_constraint}
    }
    | PQL
    wmflib::puppetdb_query($pql).map |$resource| { $resource['certname'] }.sort
}