Puppet Function: debian::codename::compare

Defined in:
modules/debian/functions/codename/compare.pp
Function type:
Puppet Language

Summary

Test if the running debian codename against the codename passed using a specific operator

Overview

debian::codename::compare(String $codename, Enum['==', '>=', '>', '<', '<=', '!='] $operator = '==', Optional[String[1]] $compare_codename = undef)Boolean

SPDX-License-Identifier: Apache-2.0

Examples:

Assuming theses functions are compiled for a host running debian buster then

debian::codename::compare('buster') == True
debian::codename::compare('stretch') == False
debian::codename::compare('stretch', '<') == False
debian::codename::compare('stretch', '>') == True
debian::codename::compare('buster', '>=') == True
debian::codename::compare('buster', '<=') == True

Parameters:

  • codename (String)

    the codename you want to test against

  • operator (Enum['==', '>=', '>', '<', '<=', '!=']) (defaults to: '==')

    the comparison operator to use

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

    An explicit codename to compare otherweise use facter

Returns:

  • (Boolean)

    result of the comparison



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'modules/debian/functions/codename/compare.pp', line 14

function debian::codename::compare (
    String                                 $codename,
    Enum['==', '>=', '>', '<', '<=', '!='] $operator         = '==',
    Optional[String[1]]                    $compare_codename = undef,
) >> Boolean {
    include debian

    $valid_codenames = $debian::supported[$facts['os']['name']]

    unless $codename in $valid_codenames {
        fail("invalid codename (${codename}). supported codenames : ${valid_codenames.keys.join(', ')}")
    }
    if $compare_codename and !($compare_codename in $valid_codenames) {
        fail("invalid codename (${compare_codename}). supported codenames : ${valid_codenames.keys.join(', ')}")
    }

    $major = $compare_codename ? {
        undef   => $debian::major,
        default => $valid_codenames[$compare_codename],
    }

    $operator ? {
        '>='    => $major >= $valid_codenames[$codename],
        '>'     => $major > $valid_codenames[$codename],
        '<='    => $major <= $valid_codenames[$codename],
        '<'     => $major < $valid_codenames[$codename],
        '!='    => $major != $valid_codenames[$codename],
        default => $major == $valid_codenames[$codename],
    }
}